How to style a checkbox using CSS

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

I am trying to style a checkbox using the following:

30条回答
  •  名媛妹妹
    2020-11-21 05:14

    You can simply use appearance: none on modern browsers, so that there is no default styling and all your styles are applied properly:

    input[type=checkbox] {
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      display: inline-block;
      width: 2em;
      height: 2em;
      border: 1px solid gray;
      outline: none;
      vertical-align: middle;
    }
    
    input[type=checkbox]:checked {
      background-color: blue;
    }
    

提交回复
热议问题