If i have several input (radio or option) followed by their label, all on the same line. How i make it so it don't break the line after the radio, but break if needed after the label.
<input type="radio" id="i1"/><label for="i1">First radio</label>
<input type="radio" id="i2"/><label for="i2">Second radio</label>
<input type="radio" id="i3"/><label for="i3">Third radio</label>
I can think of wrapping both input
and label
in a span
with nowrap
, but wonder if there's another way.
There are several ways to prevent line breaks in content. Using is one way, and works fine between words, but using it between an empty element and some text does not have a well-defined effect. The same would apply to the more logical and more accessible approach where you use an image for an icon.
You can prevent line breaks and text wrapping for specific elements using the CSS white-space property.
If you want to limit the text length to one line, you can clip the line, display an ellipsis or a custom string. All these can be done with the CSS text-overflow property, which determines how the overflowed content must be signalled to the user.
<nobr>: The Non-Breaking Text element Be aware that this feature may cease to work at any time. The <nobr> HTML element prevents the text it contains from automatically wrapping across multiple lines, potentially resulting in the user having to scroll horizontally to see the entire width of the text.
This should do the trick:
#MyDiv {width: 250px;}
<div id="MyDiv">
<nobr><input type="radio" id="i1"/><label for="i1">First radio</label></nobr>
<nobr><input type="radio" id="i2"/><label for="i2">Second radio</label></nobr>
<nobr><input type="radio" id="i3"/><label for="i3">Third radio</label></nobr>
</div>
The <nobr>
tag will ensure the break won't happen between the button and label.
CSS way is also possible, wrapping it with another <span>
and using white-space: nowrap;
should work fine.
I think this is what you're looking for: http://jsfiddle.net/catalinred/kNUaz/
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