--- title: white-space slug: Web/CSS/white-space tags: - CSS - CSS Eigenschaft - CSS Text - NeedsLiveSample - NeedsMobileBrowserCompatibility - Referenz translation_of: Web/CSS/white-space ---
Die CSS Eigenschaft white-space
wird benutzt, um Leerzeichen innerhalb eines Elementes zu handhaben.
Hinweis: Um Wörter umzubrechen, verwenden Sie stattdessen {{CSSxRef("overflow-wrap")}}, {{CSSxRef("word-break")}}, oder {{CSSxRef("hyphens")}}.
/* Schlüsselwortwerte */ white-space: normal; white-space: nowrap; white-space: pre; white-space: pre-wrap; white-space: pre-line; white-space: break-spaces; /* Globale Werte */ white-space: inherit; white-space: initial; white-space: unset;
Die Eigenschaft white-space
wird als ein einzelnes Schlüsselwort angegeben, das aus der untenstehenden Liste von Werten ausgewählt wird.
normal
nowrap
normal
, aber unterdrückt Zeilenumbrüche im Text.pre
pre-wrap
pre-line
break-spaces
pre-line
:
Die folgende Tabelle fasst das Verhalten der verschiedenen white-space
Zwischenraumzeichen zusammen:
Neue Zeilen | Leerzeichen und Tabulatoren | Textumbruch | Zeilenende-Raum | |
---|---|---|---|---|
normal |
Fallen zusammen | Fallen zusammen | Umbruch | Entfernt |
nowrap |
Fallen zusammen | Fallen zusammen | Kein Umbruch | Entfernt |
pre |
Bleiben erhalten | Bleiben erhalten | Kein Umbruch | Entfernt |
pre-wrap |
Bleiben erhalten | Bleiben erhalten | Umbruch | hängend |
pre-line |
Bleiben erhalten | Fallen zusammen | Umbruch | Entfernt |
break-space |
Bleiben erhalten | Bleiben erhalten | Umbruch | Umbruch |
{{CSSInfo}}
{{CSSSyntax}}
code { white-space: pre; }
pre { word-wrap: break-word; /* IE 5.5-7 */ white-space: pre-wrap; /* Modern browsers */ }
<div id="css-code" class="box"> p { white-space: <select> <option>normal</option> <option>nowrap</option> <option>pre</option> <option>pre-wrap</option> <option>pre-line</option> <option>break-spaces</option> </select> } </div> <div id="results" class="box"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div>
.box { width: 300px; padding: 16px; border-radius: 10px; } #css-code { background-color: rgb(220, 220, 220); font-size: 16px; font-family: monospace; } #css-code select { font-family: inherit; } #results { background-color: rgb(230, 230, 230); overflow-x: scroll; height: 400px; white-space: normal; font-size: 14px; }
var select = document.querySelector("#css-code select"); var results = document.querySelector("#results p"); select.addEventListener("change", function(e) { results.setAttribute("style", "white-space: "+e.target.value); })
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
{{EmbedLiveSample("In_action", "100%", 500)}}
Spezifikation | Status | Kommentar |
---|---|---|
{{SpecName('CSS3 Text', '#white-space', 'white-space')}} | {{Spec2('CSS3 Text')}} | Präzisiert den Umbruch-Algorithmus. Äußerlich bewirkt der white-space eine kompakte Eigenschaft. |
{{SpecName('CSS2.1', 'text.html#white-space-prop', 'white-space')}} | {{Spec2('CSS2.1')}} | Ursprüngliche Definition |
{{Compat("css.properties.white-space")}}