Custom checkbox using only CSS and HTML

后端 未结 4 1841
故里飘歌
故里飘歌 2020-12-17 15:23

I need to create a custom checkbox using only html and CSS. So far I have:

HTML/CSS:

4条回答
  •  天命终不由人
    2020-12-17 15:53

    Custom checkbox using only HTML and CSS along with three checkbox states (checked, unchecked and half checked or unchecked(if it's used in a group of checkboxes))

    
    
    .checkboxcontainer input {
      display: none;
    }
    
    .checkboxcontainer {
      display: inlin-block;
      padding-left: 30px;
      position: relative;
      cursor: pointer;
      user-select: none;
    }
    
    .checkboxcontainer .checkmark {
      display: inlin-block;
      width: 25px;
      height: 25px;
      background: #eee;
      position: absolute;
      left: 0;
      top: 0;
    }
    
    .checkboxcontainer input:checked+.checkmark {
      background-color: #2196fc;
    }
    
    .checkboxcontainer input:checked+.checkmark:after {
      content: "";
      position: absolute;
      height: 4px;
      width: 9px;
      border-left: 3px solid white;
      border-bottom: 3px solid white;
      top: 45%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(-45deg);
    }
    
    .checkboxcontainer input:indeterminate+.checkmark:after {
      content: "";
      position: absolute;
      height: 0px;
      width: 9px;
      border-left: 3px solid white;
      border-bottom: 3px solid white;
      top: 45%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(180deg);
      }
    

    Jsfiddle: Demo

提交回复
热议问题