Change checkbox label css property with checkbox checked

后端 未结 2 1364
-上瘾入骨i
-上瘾入骨i 2020-12-17 00:14

I have the following html:

  
         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 00:58

    You can achieve this with pure css like so,

    
    
    

    With this css,

    label { background-color:#333; color:#FFF; }
    
    input[type="checkbox"]:checked + label {
        background: brown;
    }
    

    JSFIDDLE

    Keep in mind

    The label has to be after the checkbox so you will need to style it around more to keep the same look you had.

    Here is an option of styling it more to have the same appearance as you wanted, New fiddle. THIS DOES NOT involve positioning anything absolute, just some trickery.

提交回复
热议问题