利用純CSS自定義Checkbox和Radio的樣式示例代碼

首先看看不同平臺(tái)的checkbox & radio
我們可以利用CSS3的一些屬性來(lái)實(shí)現(xiàn)自定義checkbox & radio樣式。
HTML 代碼
// radio input <div class="radio"> <input id="male" type="radio" name="gender" value="male"> <label for="male">Male</label> <input id="female" type="radio" name="gender" value="female"> <label for="female">Female</label> </div> // checkbox input <div class="checkbox"> <input id="check1" type="checkbox" name="check" value="check1"> <label for="check1">Checkbox No. 1</label> <input id="check2" type="checkbox" name="check" value="check2"> <label for="check2">Checkbox No. 2</label> </div>
CSS 代碼
label { display: inline-block; cursor: pointer; position: relative; padding-left: 25px; margin-right: 15px; font-size: 13px; } label:before { content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 10px; position: absolute; left: 0; bottom: 1px; background-color: #aaa; box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8); } .radio label:before { border-radius: 8px; } .checkbox label:before { border-radius: 3px; } input[type=radio], input[type=checkbox] { display: none; } input[type=radio]:checked + label:before { content: "\2022"; color: #f3f3f3; font-size: 30px; text-align: center; line-height: 18px; } input[type=checkbox]:checked + label:before { content: "\2713"; text-shadow: 1px 1px 1px rgba(0, 0, 0, .2); font-size: 15px; color: #f3f3f3; text-align: center; line-height: 15px; }
兼容性
:checked在IE8兼容性不理想
box-shadow在IE8不兼容,不過(guò)box-shadow對(duì)于自定義樣式可有可無(wú)
:after :before在IE8不兼容雙冒號(hào)寫(xiě)法
:checked屬性兼容性
box-shadow屬性兼容性
:before :after屬性兼容性
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能有所幫助,如果有疑問(wèn)大家可以留言交流。
相關(guān)文章
一款純css3實(shí)現(xiàn)簡(jiǎn)單的checkbox復(fù)選框和radio單選框
這篇文章主要為大家介紹了利用純css3實(shí)現(xiàn)一款簡(jiǎn)單實(shí)用的checkbox復(fù)選框和radio單選框,代碼簡(jiǎn)單易懂,可以直接復(fù)制,感興趣的可以進(jìn)來(lái)看看哦2014-11-05純css3實(shí)現(xiàn)效果超級(jí)炫的checkbox復(fù)選框和radio單選框
天要為大家分享的是純css3實(shí)現(xiàn)的checkbox復(fù)選框和radio單選框,效果超級(jí)炫,這個(gè)實(shí)例完全由css3實(shí)現(xiàn)的沒(méi)有任何js代碼2014-09-01CSS3實(shí)例分享--超炫checkbox復(fù)選框和radio單選框
這篇文章主要介紹了CSS3實(shí)例分享--超炫checkbox復(fù)選框和radio單選框,需要的朋友可以參考下2014-09-01css3和jquery實(shí)現(xiàn)自定義checkbox和radiobox組件
這篇文章主要介紹了css3和jquery實(shí)現(xiàn)自定義美化Checkbox和Radiobox組件的示例,需要的朋友可以參考下2014-04-22CSS 點(diǎn)擊radio實(shí)現(xiàn)兩個(gè)圖片樣式切換并且多個(gè)radio中只能有一個(gè)checked
這篇文章主要介紹了CSS 點(diǎn)擊radio實(shí)現(xiàn)兩個(gè)圖片樣式切換并且多個(gè)radio中只能有一個(gè)checked,感興趣的朋友跟隨小編一起看看吧2019-12-11