1

I want to have a list of check boxes down the page, which has a label, as shown in the following layout:

My options  [x] Checkbox 1
            [ ] Checkbox 2
            [ ] Checkbox 3
            [ ] Checkbox 4

I'm using the method outlined here What is the best way to style a list of checkboxes in the answer by @Magnar. This works fine, but when I wrap the checkbox text as labels, the checkboxes list horizontally across the page in IE (Chrome and Firefox still render it fine).

My HTML:

<div id="options">
  <label>My options</label>
  <ul>
    <li><label><input type="checkbox">Checkbox 1</label></li>
    <li><label><input type="checkbox">Checkbox 2</label></li>
    <li><label><input type="checkbox">Checkbox 3</label></li>
    <li><label><input type="checkbox">Checkbox 4</label></li>
  </ul>
</div>

My CSS:

#options label {
  float: left;
}

#options ul {
  margin: 0;
  list-style: none;
  float: left;
}

If someone could help me get it to work nicely in IE too I'd really appreciate it. I'd also love to know why it works everywhere but IE :).

Community
  • 1
  • 1
Chris Anderson
  • 8,279
  • 2
  • 20
  • 18

3 Answers3

2

This will solve the issue in IE.

#options label {
  float: left;
  clear: left;
}

clear makes the element drop below any floated elements that precede it in the document.
A good diagramatic example is available in https://stackoverflow.com/a/1012141/1671639.

Check this JSFiddle in IE.

Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
1

html

<div id="options">
  <label>My options</label>
  <ul>
    <li>
           <input type="checkbox">
           <label>Checkbox 1</label>
           <div style="clear:both"></div>
        </li>
    <li>
        <input type="checkbox">
        <label>Checkbox 2</label>
        <div style="clear:both"></div>
    </li>
    <li>
        <input type="checkbox">
        <label>Checkbox 3</label>
        <div style="clear:both"></div>
    </li>
    <li>
        <input type="checkbox">
        <label>Checkbox 4</label>
        <div style="clear:both"></div>
    </li>
  </ul>
</div>

css

#options label {
  float: left;
}

#options ul {
  margin: 0;
  list-style: none;
  float: left;
}
#options ul input{
    float:left;
}

Working Demo

Abdul Malik
  • 2,632
  • 1
  • 18
  • 31
  • Thanks for your answer Abdul. Ultimately very similar in concept to that provided by user1671639, but their answer required just one line of css rather than additional divs in the HTML. Gave you an upvote for your effort. – Chris Anderson Jun 26 '13 at 05:58
0

You can always use http://csscheckbox.com/ to create styled check boxes.

They say that their styled checkboxes are working in IE.

I hope this will help you!!!