How do I style (css) radio buttons and labels?

前端 未结 3 859
天命终不由人
天命终不由人 2020-12-23 14:12

Given the code bellow, how do I style the radio buttons to be next to the labels and style the label of the selected radio button differently than the other labels?

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 14:51

    For any CSS3-enabled browser you can use an adjacent sibling selector for styling your labels

    input:checked + label {
        color: white;
    }  
    

    MDN's browser compatibility table says essentially all of the current, popular browsers (Chrome, IE, Firefox, Safari), on both desktop and mobile, are compatible.

提交回复
热议问题