input標籤與label標籤的「合做關係」

一直忽略了input和label的關係。一次在作自定義單選框的時候又從新撿起來這對「兄弟」。html

label的for屬性和input的id值一致的話,input和label就會組成一個組。例如:git

<label for="test">
    <input type="checkbox" id="test" abc="1111" />
</label>

點擊label的區域一樣會觸發到input的選中效果。利用這一特性,而後結合僞元素能夠自定義單選框和單選按鈕。github

詳細代碼可看:https://github.com/IT-girl-lijia/BaiduWebSchool/blob/master/BaiduNuomi_task1/index.htmlspa

代碼效果:http://htmlpreview.github.io/?https://github.com/IT-girl-lijia/BaiduWebSchool/blob/master/BaiduNuomi_task1/index.htmlcode

相關文章
相關標籤/搜索