Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nowrap / Don't break the line after a input

Tags:

html

css

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.

like image 981
ariel Avatar asked Sep 22 '11 06:09

ariel


People also ask

How do you not break a line?

There are several ways to prevent line breaks in content. Using &nbsp; 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.

How do you prevent a line from breaking in CSS?

You can prevent line breaks and text wrapping for specific elements using the CSS white-space property.

How do I make text stay on one line in CSS?

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.

How do you make text not break in HTML?

<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.


2 Answers

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.

like image 178
Shadow Wizard Hates Omicron Avatar answered Sep 28 '22 19:09

Shadow Wizard Hates Omicron


I think this is what you're looking for: http://jsfiddle.net/catalinred/kNUaz/

like image 28
Red Avatar answered Sep 28 '22 19:09

Red