Style checkboxes as Toggle Buttons

后端 未结 5 1406
太阳男子
太阳男子 2021-02-20 14:18

On my website, users can post articles and tag them accordingly using some pre-set tags. These tags are in the form of checkboxes. Example below:



        
5条回答
  •  醉酒成梦
    2021-02-20 15:06

    Check this out

    HTML

    
    
    
    
    
    
    
    
    

    CSS

    .vis-hidden {
        border: 0;
        clip: rect(0 0 0 0);
        height: 1px;
        margin: -1px;
        overflow: hidden;
        padding: 0;
        position: absolute;
        width: 1px;
    }
    
    label {
      margin: 10px;
      padding: 5px;
      border: 1px solid gray;
    }
    
    input:focus + label {
      border-color: blue;
    }
    
    input:checked + label {
      border-color: red;
    }
    
    input:focus:checked + label {
      border-color: green;
    }
    

    Note that the last selector may not work in older IE.

提交回复
热议问题