摘要:現(xiàn)在前端頁面效果日益豐富,默認(rèn)的組件樣式顯然已經(jīng)不能滿足需求。兼容更低版本瀏覽器的樣式修改最后附上演示鏈接修改和默認(rèn)樣式
radio and checkbox現(xiàn)在前端頁面效果日益豐富,默認(rèn)的input組件樣式顯然已經(jīng)不能滿足需求。趁著這次開發(fā)的頁面中有這方面的需求,在這里整理一下修改radio、checkbox、select的方法。
修改radio的默認(rèn)樣式有兩種常用的方法
純CSS此方法需借助CSS3,關(guān)鍵CSS代碼如下
.demo1 input[type="radio"],.demo1 input[type="checkbox"]{ display:none; } .demo1 label:before{ content: ""; display: inline-block; width: 17px; height: 16px; margin-right: 10px; position: absolute; left: 0; bottom: 0; background-color: #3797fc; } .demo1 input[type="radio"] + label:before{ border-radius: 8px; } .demo1 input[type="checkbox"] + label:before{ border-radius: 3px; } .demo1 input[type="radio"]:checked+label:before{ content: "2022"; color: #fff; font-size: 30px; text-align: center; line-height: 19px; } .demo1 input[type="checkbox"]:checked+label:before{ content: "2713"; font-size: 15px; color: #f3f3f3; text-align: center; line-height: 17px; }
優(yōu)點:充分借助了CSS3的優(yōu)勢,無需使用js和圖片,僅用純CSS3就可搞定
缺點:兼容性較差,僅支持IE9+
js+圖片js代碼:
$(function(){ $(".demospan").bind("click",function(){ $(this).addClass("on").siblings().removeClass("on"); }) $(".piaochecked").bind("click",function(){ $(this).hasClass("on_check")?$(this).removeClass("on_check"):$(this).addClass("on_check"); // $(this).toggleClass("on_check"); }) })
css代碼
.demospan{ display: inline-block; width: 24px; height: 18px; /*float: left;*/ padding-top: 3px; cursor: pointer; text-align: center; margin-right: 10px; background-image: url(http://sandbox.runjs.cn/uploads/rs/161/i5pmsg7s/inputradio.gif); background-repeat: no-repeat; background-position: -24px 0; } .demo21{ opacity: 0; cursor: pointer; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); } .on{ background-position: 0 0; } .piaochecked{ display: inline-block; width: 20px; height: 20px; cursor: pointer; margin-left: 10px; text-align: center; background-image: url(http://sandbox.runjs.cn/uploads/rs/161/i5pmsg7s/checkbox_01.gif); background-repeat: no-repeat; background-position: 0 0; } .on_check{ background-position: 0 -21px; } .cbdemo2{ opacity: 0; cursor: pointer; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=0)"; filter:alpha(opacity=0); }
優(yōu)點:兼容性高,支持IE6+
缺點:使用js+圖片較為麻煩
select/*select*/ .select select{ /*復(fù)寫Chrome和Firefox里面的邊框*/ border:1px solid green; /*清除默認(rèn)樣式*/ appearance:none; -moz-appearance:none; -webkit-appearance:none; /*在選擇框的最右側(cè)中間顯示小箭頭圖片*/ background: url("http://ourjs.github.io/static/2015/arrow.png") no-repeat scroll right center transparent; /*為下拉小箭頭留出一點位置,避免被文字覆蓋*/ padding-right: 14px; } /*清除ie的默認(rèn)選擇框樣式清除,隱藏下拉箭頭*/ select::-ms-expand { display: none; }
該方法關(guān)鍵在于清除默認(rèn)樣式,使用css3的appearance屬性,但是兼容性較差,僅支持IE9+。若要兼容低版本瀏覽器,可以使用Div進(jìn)行模擬。
//Todo
兼容更低版本瀏覽器的select樣式修改
最后附上演示鏈接:修改radio、checkbox和select默認(rèn)樣式
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/86281.html
摘要:現(xiàn)在前端頁面效果日益豐富,默認(rèn)的組件樣式顯然不能滿足設(shè)計需求。前段時間開發(fā)項目中剛好接觸到相關(guān)的需求,在此特地整理下修改樣式的方法。它使用純編寫,沒有任何的文件。 現(xiàn)在前端頁面效果日益豐富,默認(rèn)的input組件樣式顯然不能滿足設(shè)計需求。前段時間開發(fā)項目中剛好接觸到相關(guān)的需求,在此特地整理下修改radio、CheckBox樣式的方法。 原理:大致原理都是使用原生的checkbox或inp...
摘要:現(xiàn)在前端頁面效果日益豐富,默認(rèn)的組件樣式顯然不能滿足設(shè)計需求。前段時間開發(fā)項目中剛好接觸到相關(guān)的需求,在此特地整理下修改樣式的方法。它使用純編寫,沒有任何的文件。 現(xiàn)在前端頁面效果日益豐富,默認(rèn)的input組件樣式顯然不能滿足設(shè)計需求。前段時間開發(fā)項目中剛好接觸到相關(guān)的需求,在此特地整理下修改radio、CheckBox樣式的方法。 原理:大致原理都是使用原生的checkbox或inp...
摘要:常見操作常見操作常見操作常見操作代碼下拉框單選框多選框代碼常見操作常見操作獲取選中值第一種通過對象獲取第二種通過選中的下標(biāo)來獲取獲取獲取選中文本值通過選中的下標(biāo)來獲取選中文本值設(shè)置選中項知道的值或者下標(biāo)或者文本值下面代碼只列出根據(jù)來選中獲取 select、radio 、checkbox常見操作 select常見操作 radio常見操作 select常見操作 html代碼 ...
摘要:常見操作常見操作常見操作常見操作代碼下拉框單選框多選框代碼常見操作常見操作獲取選中值第一種通過對象獲取第二種通過選中的下標(biāo)來獲取獲取獲取選中文本值通過選中的下標(biāo)來獲取選中文本值設(shè)置選中項知道的值或者下標(biāo)或者文本值下面代碼只列出根據(jù)來選中獲取 select、radio 、checkbox常見操作 select常見操作 radio常見操作 select常見操作 html代碼 ...
閱讀 2079·2021-10-12 10:12
閱讀 797·2021-09-24 09:47
閱讀 1198·2021-08-19 11:12
閱讀 3486·2019-08-29 13:06
閱讀 695·2019-08-26 11:43
閱讀 2581·2019-08-23 17:20
閱讀 1159·2019-08-23 16:52
閱讀 2607·2019-08-23 14:27