I have a simple structure of:
<div></div><span></span><span></span>
but I want to force them all on one line! at the moment, they appear:
<div />
<span /><span />
unfortunately, I HAVE to have the first element as a div; the div is acting as a bar from a bar chart (so rounded corners, width = jquery stuff, no content and block colour inside), the next span is the value the bar represents and the last span is what the value is associated to.
so I want
[____________] 25% ObjectA
[________________________] 50% ObjectB
[______] 12.5% ObjectC
[______] 12.5% ObjectD
and not
[____________]
25% ObjectA
[________________________]
50% ObjectB
[______]
12.5% ObjectC
[______]
12.5% ObjectD
To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.
In the wrapping div you should have: display: flex; align-items: center; and remove the display property from both elements.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
A <span style="display:block"></span> will indeed behave like a div element. In such case the difference is a semantic one, as divs are meant to be containers while spans are wrappers for sections of text or other inline content.
Put the CSS property display: inline-block
on the div to make it act like an inline element instead of taking up the whole line.
Edit:
@Mr_Green's suggestion to use the after
pseudo-element to clear each line is absolutely necessary to prevent a broken layout.
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