0

I'm unable to do any styling whatsoever on some HTML checkboxes. Any css fails to change the appearance of the checkboxes:

HTML:

<input type="checkbox" id="checkbox-1-1" class="regular-checkbox" />
    <nput type="checkbox" id="checkbox-1-2" class="regular-checkbox" />
    <input type="checkbox" id="checkbox-1-3" class="regular-checkbox" />
    <input type="checkbox" id="checkbox-1-4" class="regular-checkbox" />

CSS:

.regular-checkbox {
  position: absolute;
  top: 0;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #eee;
}

Checkbox is unchanged. Can anyone tell me what I'm doing wrong here? I thought this was possible in CSS.

DiamondJoe12
  • 1,879
  • 7
  • 33
  • 81
  • What's `nput`? You probably meant `input` for that second input line. – miike3459 Nov 27 '18 at 23:58
  • 1
    https://stackoverflow.com/questions/4148499/how-to-style-a-checkbox-using-css – epascarello Nov 27 '18 at 23:58
  • Your statement "I'm unable to do any styling whatsoever on some HTML checkboxes" is incorrect, see: http://jsfiddle.net/y38jc2k0/ . Positioning and size have worked as expected .... background color, now that is a different story. As per the previous comment, there are some "issues" when it comes to styling checkboxes and radio buttons. – Jon P Nov 28 '18 at 00:18

2 Answers2

1

Let me know if it helps or you need some explanation.

<!DOCTYPE html>
<html>
<style>
  .container {
    display: block;
    position: relative;
    padding-left: 35px;
    margin-bottom: 12px;
    cursor: pointer;
    font-size: 22px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }
  
  .container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
  }
  
  .checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 25px;
    width: 25px;
    background-color: #eee;
  }
  
  .container:hover input~.checkmark {
    background-color: #ccc;
  }
  
  .container input:checked~.checkmark {
    background-color: #2196F3;
  }
  
  .checkmark:after {
    content: "";
    position: absolute;
    display: none;
  }
  
  .container input:checked~.checkmark:after {
    display: block;
  }
  
  .container .checkmark:after {
    left: 9px;
    top: 5px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
  }
</style>

<body>

  <label class="container">One
  <input type="checkbox">
  <span class="checkmark"></span>
</label>

</body>

</html>
AbhaY
  • 126
  • 7
  • A good answer should explain what it does and why and not just rely on code to do the talking. – Jon P Nov 28 '18 at 00:19
0

It's not possible to style checkbox inputs (nor radios) in css.

But you can create a custom checkbox and add a hidden checkbox or something like that. Which is what most people do because it can easily be compatible across browsers.

CSPP
  • 126
  • 3