How to style a checkbox using CSS

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

I am trying to style a checkbox using the following:

30条回答
  •  抹茶落季
    2020-11-21 05:17

    My solution

    input[type="checkbox"] {
      cursor: pointer;
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      outline: 0;
      background: lightgray;
      height: 16px;
      width: 16px;
      border: 1px solid white;
    }
    
    input[type="checkbox"]:checked {
      background: #2aa1c0;
    }
    
    input[type="checkbox"]:hover {
      filter: brightness(90%);
    }
    
    input[type="checkbox"]:disabled {
      background: #e6e6e6;
      opacity: 0.6;
      pointer-events: none;
    }
    
    input[type="checkbox"]:after {
      content: '';
      position: relative;
      left: 40%;
      top: 20%;
      width: 15%;
      height: 40%;
      border: solid #fff;
      border-width: 0 2px 2px 0;
      transform: rotate(45deg);
      display: none;
    }
    
    input[type="checkbox"]:checked:after {
      display: block;
    }
    
    input[type="checkbox"]:disabled:after {
      border-color: #7b7b7b;
    }




提交回复
热议问题