How can I make an element automatically be positioned on a new line in the page? In HTML I could use <br>
, but how do I add something like a line-break in CSS?
Say I have the following code for example:
<p>Lorem ipsum dolor sit amet, <span id="elementId">consectetur adipisicing elit.</span> Magni totam velit ex delectus fuga fugit</p>
The span is still positioned on the same line as the rest of the text. How can I move the span text on a new line purely through CSS?
Another example is when using display: inline-block
or float
:
<div class="smalldiv">Lorem ipsum dolor sit amet</div> <div class="smalldiv">Lorem ipsum dolor sit amet</div> <div class="smalldiv" id="elementId">Lorem ipsum dolor sit amet</div> <div class="smalldiv">Lorem ipsum dolor sit amet</div> .smalldiv { display: inline-block; // OR float: left; }
How can I move one of the <div>
s on a new line to create a new row?
Set size and make inline Because they're block elements, when reducing the size of Div one to make room for the other div, you're left with space next to Div one and Div two below Div one. To move the div up to the next line both div's need to have the inline-block display setting as shown below.
In HTML, the <br> element creates a line break. You can add it wherever you want text to end on the current line and resume on the next.
There are two options that I can think of, but without more details, I can't be sure which is the better:
#elementId { display: block; }
This will force the element to a 'new line' if it's not on the same line as a floated element.
#elementId { clear: both; }
This will force the element to clear the floats, and move to a 'new line.'
In the case of the element being on the same line as another that has position
of fixed
or absolute
nothing will, so far as I know, force a 'new line,' as those elements are removed from the document's normal flow.
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