Adminiculo
Adminiculo

Reputation: 333

CSS :after pseudo checkbox not working in IE or Firebug

I have the styling below to achieve a pseudo checkbox. In real life it has a background image to show the marks I want, but I simplified the example for researching purposes. It's working nicely in Chrome and Safari, but not in firefox or IE. Another set of eyes would be much appreciated.

http://www.bootply.com/6xig9trE5C

CODE:

/*CSS*/
ul {
  margin: 0 auto;
  width: 270px;
}
li {
  float: left;
  height: 30px;
  list-style-type: none;
  text-align: left;
  white-space: nowrap;
  width: 50%;
}

input[type=checkbox] {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  left: -2000px;
  margin: -1px;
  padding: 0;
  position: relative;
  width: 1px;
}
input[type=checkbox]:after {
  content: 'X';
  display: inline-block;
  height: 19px;
  left: 1969px;
  position: relative;
  top: -12px;
  width: 19px;
}
input[type=checkbox]:checked:after {
  content: 'V';
}

label {
  cursor: pointer;
  display: inline-block;
  font-size: 15px;
  height: 27px;
  line-height: 22px;
  padding-left: 32px;
  -khtml-user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

<!-- HTML -->
<div class="option">
  <ul>
    <li>
      <label><input name="cb1" type="checkbox" checked="checked" value="1">Checkbox1</label>
    </li>
    <li>
      <label><input name="cb2" type="checkbox" checked="checked" value="2">Checkbox2</label>
    </li>
    <li>
      <label><input name="cb3" type="checkbox" checked="checked" value="3">Checkbox3</label>
    </li>
  </ul>
</div>

Upvotes: 2

Views: 2034

Answers (2)

Adminiculo
Adminiculo

Reputation: 333

In this case, knowing what the problem was, I fixed it by adding an empty span after the input and using there the styling of the :after, with little modifications. Like this:

<!-- html -->
<label>
   <input type="checkbox" checked="checked" value="1" name="cb1">
   <span></span>
   Checkbox 1
</label> 

/*CSS: (with the background use)*/
input[type=checkbox] + span {
  background: url("/img/checkbox.png") 0 0 no-repeat;
  display: inline-block;
  height: 19px;
  left: -12px;
  position: relative;
  top: 3px;
  width: 19px;
}

input[type=checkbox]:checked + span {
  background-position: 0 -32px;
}

Upvotes: 1

Kheema Pandey
Kheema Pandey

Reputation: 10265

:before and :after pseudo elements add new content before or after the target element's content. Since Input elements have no content; they just have a value. so technically we can't use pseudo element for input element.

so I guess in this case chrome Browser is wrong. and IE and Firefox Browser are right.

you may have a look what w3c says.

Upvotes: 2

Related Questions