How to style a checkbox using CSS

前端 未结 30 3427
日久生厌
日久生厌 2020-11-21 04:26

I am trying to style a checkbox using the following:

30条回答
  •  一生所求
    2020-11-21 05:06

    There is a way to do this using just CSS. We can (ab)use the label element and style that element instead. The caveat is that this will not work for Internet Explorer 8 and lower versions.

    .myCheckbox input {
      position: relative;
      z-index: -9999;
    }
    
    .myCheckbox span {
      width: 20px;
      height: 20px;
      display: block;
      background: url("link_to_image");
    }
    
    .myCheckbox input:checked + span {
      background: url("link_to_another_image");
    }
    
    

提交回复
热议问题