Should I put input elements inside a label element?

前端 未结 14 1821
长情又很酷
长情又很酷 2020-11-22 07:24

Is there a best practice concerning the nesting of label and input HTML elements?

classic way:



        
14条回答
  •  长情又很酷
    2020-11-22 08:07

    From w3:

    The label itself may be positioned before, after or around the associated control.


    
    

    or

    
    

    or

    Note that the third technique cannot be used when a table is being used for layout, with the label in one cell and its associated form field in another cell.

    Either one is valid. I like to use either the first or second example, as it gives you more style control.

提交回复
热议问题