Using “label for” on radio buttons

前端 未结 3 566
深忆病人
深忆病人 2020-12-04 14:05

When using the \"label for\" parameter on radio buttons, to be 508 compliant*, is the following correct?

 
3条回答
  •  一向
    一向 (楼主)
    2020-12-04 14:28

    Either structure is valid and accessible, but the for attribute should be equal to the id of the input element:

    
    

    or

    
    

    The for attribute is optional in the second version (label containing input), but IIRC there were some older browsers that didn't make the label text clickable unless you included it. The first version (label after input) is easier to style with CSS using the adjacent sibling selector +:

    input[type="radio"]:checked+label {font-weight:bold;}
    

提交回复
热议问题