Home >Web Front-end >CSS Tutorial >How Can I Display DIV Elements Horizontally Instead of Vertically?
Displaying DIV Elements Inline
The HTML code provided displays DIV elements in a stacked manner, one below the other. The desired outcome, however, is to have these DIVs displayed inline, horizontally aligned.
In the provided HTML:
<div>foo</div><div>bar</div><div>baz</div>
These DIVs will appear as three separate lines, with "foo" on the first line, "bar" on the second, and "baz" on the third.
To display these DIVs inline, it is recommended to use SPAN elements instead. SPAN elements, by default, display inline, which means they will line up horizontally. The modified code would look like this:
<span>foo</span><span>bar</span><span>baz</span>
Now, when rendered, "foo", "bar", and "baz" will appear alongside each other on the same line.
It is important to note that inline DIVs are not standard and can lead to unpredictable behavior. In most cases, it is best practice to use SPAN elements for inline display instead.
The above is the detailed content of How Can I Display DIV Elements Horizontally Instead of Vertically?. For more information, please follow other related articles on the PHP Chinese website!