Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align the checkbox and label in same line in html?

Tags:

html

css

Within li tags, I am placing a checkbox and label input.

If label text is larger than label, the text goes to the next line.

I wrapped the label text but it's not aligning the checkbox and label in the same line if label text is too long.

<li>     <input id="checkid" type="checkbox" value="test" />     <label style="word-wrap:break-word">testdata</label> </li> 

Thanks,

like image 849
user3392135 Avatar asked Mar 11 '14 09:03

user3392135


People also ask

How can I get checkbox and label on same line?

Method 1: By making the position of checkbox relative, set the vertical-align to the middle can align the checkboxes and their labels. Here, we have made the position of the checkbox relative to the label. So the checkboxes are aligned according to the label.

How do you align text boxes and labels in HTML?

To align the boxes, add a div wrapper around each label/input, make your label inline-block with a fixed width.

How do I keep a checkbox on the same line?

'white-space: nowrap' is the trick I was looking for. Thanks.

How do I add a checkbox to a label in HTML?

The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices. Tip: Always add the <label> tag for best accessibility practices!


1 Answers

Wrap the checkbox with the label and check this

HTML:

<li>      <label for="checkid"  style="word-wrap:break-word">         <input id="checkid"  type="checkbox" value="test" />testdata      </label> </li> 

CSS:

[type="checkbox"] {     vertical-align:middle; } 

http://jsfiddle.net/pKD9K/1/

like image 93
Ijas Ameenudeen Avatar answered Sep 20 '22 13:09

Ijas Ameenudeen