Style whiteSpace- Eigenschaft
Beispiel
Geben Sie an, dass der Text im <div>-Element niemals umbrochen wird:
document.getElementById("myDIV").style.whiteSpace = "nowrap";
Definition und Verwendung
Die Eigenschaft whiteSpace legt fest oder gibt zurück, wie mit Tabulatoren, Zeilenumbrüchen und Leerzeichen in einem Text umgegangen wird.
Browser-Unterstützung
Property | |||||
---|---|---|---|---|---|
whiteSpace | Yes | Yes | Yes | Yes | Yes |
Syntax
Geben Sie die whiteSpace-Eigenschaft zurück:
object.style.whiteSpace
Legen Sie die whiteSpace-Eigenschaft fest:
object.style.whiteSpace = "normal|nowrap|pre|initial|inherit"
Eigenschaftswerte
Value | Description |
---|---|
normal | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default |
nowrap | Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered |
pre | Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML |
pre-line | Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks |
pre-wrap | Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technische Details
Standardwert: | normal |
---|---|
Rückgabewert: | Ein String, der darstellt, wie Leerzeichen innerhalb eines Elements gehandhabt werden |
CSS-Version | CSS1 |
Mehr Beispiele
Beispiel
Gibt die whiteSpace-Eigenschaft zurück
alert(document.getElementById("myDiv").style.whiteSpace);
Verwandte Seiten
CSS-Tutorial: CSS-Text
CSS-Referenz: Whitespace-Eigenschaft
❮ Style-Objekt