Is it possible to break line on white space and place the next word on a new line?
In the following example the result should look like the second title :
.test{
text-align:center;
}
h1{
display:inline-block;
}
span{
position:relative;
top:50px;
right:45px;
}
<div class="test">
<h1>split this</h1>
<h2>split <span>this</span> </h2>
</div>
Is it possible to break lines on each white space?
A white space can be a sequence of spaces (entered using the space or the tab keys) or a line break (entered using the carriage return key (or the Enter key), or <br/> ). This property will specify how the white spaces in the source code of an element will be handled inside the element when rendered on the page.
pre-line. Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks.
White space refers to empty or blank values in the code which the browser reads and renders. Html has a special feature of collapsing these white spaces. If you put extra/consecutive white spaces or newlines in the code it will regard it as one white space this is known as collapsing of white spaces.
nowrap : Multiple whitespaces are collapsed into one, but the text doesn't wrap to the next line.
You could use a very high value for the word-spacing property. It will break lines on each white space between words :
.test{
text-align:center;
}
h1{
word-spacing:9999px;
}
<div class="test">
<h1>split this</h1>
</div>
You could use word-wrap
in your CSS to make sure your words are not cut out and are forced in the next line if the size of your content area doesn't fit in.
Like following:
h1 {
word-wrap: break-word;
}
If you instead would break the word, no matter the point of break (causes the word to break from the point where it doesn't fit to the area anymore) you can use word-break
.
h1 {
word-break: break-all;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With