純css實(shí)現(xiàn)一款仿ios7的switches開關(guān)按鈕

今天給大家介紹一款仿ios7的switches開關(guān)按鈕。這款按鈕也是純css實(shí)現(xiàn)的。無(wú)需引js代碼。在實(shí)現(xiàn)中給出了兩種顏色,三種不同大小的demo。一起看下效果圖:
實(shí)現(xiàn)的代碼。
html代碼:
<h1>
iOS 7 style switches with CSS</h1>
<h2>
By Bandar Raffah</h2>
<label>
Big<input type="checkbox" class="ios-switch green bigswitch" checked /><div>
<div>
</div>
</div>
</label>
<label>
<input type="checkbox" class="ios-switch bigswitch" checked /><div>
<div>
</div>
</div>
</label>
<label>
Normal<input type="checkbox" class="ios-switch green" /><div>
<div>
</div>
</div>
</label>
<label>
<input type="checkbox" class="ios-switch" /><div>
<div>
</div>
</div>
</label>
<label>
Tiny<input type="checkbox" class="ios-switch green tinyswitch" checked /><div>
<div>
</div>
</div>
</label>
<label>
<input type="checkbox" class="ios-switch tinyswitch" checked /><div>
<div>
</div>
</div>
</label>
</div>
css代碼:
{
position: absolute;
opacity: 0;
}
/* Normal Track */
input[type="checkbox"].ios-switch + div
{
vertical-align: middle;
width: 40px;
height: 20px;
border: 1px solid rgba(0,0,0,.4);
border-radius: 999px;
background-color: rgba(0, 0, 0, 0.1);
-webkit-transition-duration: .4s;
-webkit-transition-property: background-color, box-shadow;
box-shadow: inset 0 0 0 0px rgba(0,0,0,0.4);
margin: 15px 1.2em 15px 2.5em;
}
/* Checked Track (Blue) */
input[type="checkbox"].ios-switch:checked + div
{
width: 40px;
background-position: 0 0;
background-color: #3b89ec;
border: 1px solid #0e62cd;
box-shadow: inset 0 0 0 10px rgba(59,137,259,1);
}
/* Tiny Track */
input[type="checkbox"].tinyswitch.ios-switch + div
{
width: 34px;
height: 18px;
}
/* Big Track */
input[type="checkbox"].bigswitch.ios-switch + div
{
width: 50px;
height: 25px;
}
/* Green Track */
input[type="checkbox"].green.ios-switch:checked + div
{
background-color: #00e359;
border: 1px solid rgba(0, 162, 63,1);
box-shadow: inset 0 0 0 10px rgba(0,227,89,1);
}
/* Normal Knob */
input[type="checkbox"].ios-switch + div > div
{
float: left;
width: 18px;
height: 18px;
border-radius: inherit;
background: #ffffff;
-webkit-transition-timing-function: cubic-bezier(.54,1.85,.5,1);
-webkit-transition-duration: 0.4s;
-webkit-transition-property: transform, background-color, box-shadow;
-moz-transition-timing-function: cubic-bezier(.54,1.85,.5,1);
-moz-transition-duration: 0.4s;
-moz-transition-property: transform, background-color;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3), 0px 0px 0 1px rgba(0, 0, 0, 0.4);
pointer-events: none;
margin-top: 1px;
margin-left: 1px;
}
/* Checked Knob (Blue Style) */
input[type="checkbox"].ios-switch:checked + div > div
{
-webkit-transform: translate3d(20px, 0, 0);
-moz-transform: translate3d(20px, 0, 0);
background-color: #ffffff;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3), 0px 0px 0 1px rgba(8, 80, 172,1);
}
/* Tiny Knob */
input[type="checkbox"].tinyswitch.ios-switch + div > div
{
width: 16px;
height: 16px;
margin-top: 1px;
}
/* Checked Tiny Knob (Blue Style) */
input[type="checkbox"].tinyswitch.ios-switch:checked + div > div
{
-webkit-transform: translate3d(16px, 0, 0);
-moz-transform: translate3d(16px, 0, 0);
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3), 0px 0px 0 1px rgba(8, 80, 172,1);
}
/* Big Knob */
input[type="checkbox"].bigswitch.ios-switch + div > div
{
width: 23px;
height: 23px;
margin-top: 1px;
}
/* Checked Big Knob (Blue Style) */
input[type="checkbox"].bigswitch.ios-switch:checked + div > div
{
-webkit-transform: translate3d(25px, 0, 0);
-moz-transform: translate3d(16px, 0, 0);
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3), 0px 0px 0 1px rgba(8, 80, 172,1);
}
/* Green Knob */
input[type="checkbox"].green.ios-switch:checked + div > div
{
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 162, 63,1);
}
/* Needless Page Decoration */
body
{
-webkit-user-select: none;
cursor: default;
font: 18px "Helvetica Neue";
color: rgba(0, 0, 0, 0.77);
font-weight: 200;
padding-left: 30px;
padding-top: 0px;
background: -webkit-linear-gradient(top, #f2fbff 0%, #ffffff 64%) no-repeat;
background: -moz-linear-gradient(top, #f2fbff 0%, #ffffff 64%) no-repeat;
background: -ms-linear-gradient(top, #f2fbff 0%, #ffffff 64%) no-repeat;
background: linear-gradient(to bottom, #f2fbff 0%, #ffffff 64%) no-repeat;
}
h1
{
font-weight: 100;
font-size: 40px;
color: #135ae4;
}
h2
{
font-weight: 200;
font-size: 22px;
color: #03b000;
}
h3
{
font-weight: 200;
font-size: 18px;
color: rgba(0, 0, 0, 0.77);
margin-top: 50px;
}
a:link
{
text-decoration: none;
color: #f06;
}
a:visited
{
text-decoration: none;
color: #f06;
}
a:hover
{
text-decoration: underline;
}
a:active
{
text-decoration: underline;
}
相關(guān)文章
如何用css3實(shí)現(xiàn)switch組件開關(guān)的方法
這篇文章主要介紹了如何用css3實(shí)現(xiàn)switch組件的方法的相關(guān)資料,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-09CSS3實(shí)現(xiàn)的多組創(chuàng)意互動(dòng)式開關(guān)切換按鈕動(dòng)畫特效源碼
CSS3實(shí)現(xiàn)的創(chuàng)意互動(dòng)式開關(guān)切換按鈕特效源碼是一段實(shí)現(xiàn)了多組創(chuàng)意的CSS3動(dòng)畫按鈕特效,如:白天黑夜、難過(guò)開心、高亮等等,非常實(shí)用,歡迎有需要的朋友前來(lái)下載使用2018-01-26CSS3美化單選/復(fù)選/開關(guān)按鈕樣式特效源碼
CSS3美化單選/復(fù)選/開關(guān)按鈕樣式特效源碼是一款純CSS3的單選框,復(fù)選框,開關(guān)按鈕UI庫(kù),實(shí)現(xiàn)了按鈕可選和按鈕不可選的效果,非常不錯(cuò),歡迎有需要的朋友前來(lái)下載使用2017-12-21純CSS3實(shí)現(xiàn)漂亮的點(diǎn)擊開關(guān)切換動(dòng)畫效果源碼
這是一款基于純CSS3實(shí)現(xiàn)漂亮的點(diǎn)擊開關(guān)切換動(dòng)畫效果源碼。界面上的開關(guān)按鈕點(diǎn)擊時(shí)可呈現(xiàn)出帶有彈性翻牌動(dòng)作的動(dòng)畫視覺效果2017-11-02純CSS3實(shí)現(xiàn)的炫酷checkbox復(fù)選框美化庫(kù)checkboxes.css(含開關(guān)按鈕美化
checkboxes.css是一款純CSS3炫酷checkbox復(fù)選框美化庫(kù)。checkboxes.css可以通過(guò)在HTML代碼中簡(jiǎn)單的class配置,生成多種不同效果的checkbox美化樣式,其中包括復(fù)選框按鈕美2017-09-05純css3實(shí)現(xiàn)的仿窗簾拉開關(guān)閉百葉窗動(dòng)畫特效源碼
這是一款基于純css3實(shí)現(xiàn)的仿窗簾拉開關(guān)閉百葉窗動(dòng)畫特效源碼。右側(cè)有兩個(gè)下拉桿,可點(diǎn)擊控制百葉窗的打開與折疊收起等動(dòng)畫效果。2017-06-22- 這篇文章主要為大家詳細(xì)介紹了CSS3模擬IOS滑動(dòng)開關(guān)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-28
純CSS3實(shí)現(xiàn)精美的滑動(dòng)開關(guān)按鈕特效
本特效是一組使用CSS3制作的精美滑動(dòng)開關(guān)按鈕效果的代碼,這組滑動(dòng)按鈕按Bootstrap的情景類來(lái)設(shè)計(jì),可以適應(yīng)5種不同的場(chǎng)景2016-09-23純CSS3簡(jiǎn)單的滑動(dòng)開關(guān)按鈕特效源碼
本源碼是一個(gè)使用純CSS3制作的滑動(dòng)開關(guān)按鈕特效的代碼。使用偽元素來(lái)制作外觀,制作出4種安卓樣式特效2016-04-07純CSS3實(shí)現(xiàn)的開關(guān)按鈕動(dòng)畫特效源碼
是一款可以使用鼠標(biāo)來(lái)控制開關(guān)滑動(dòng),按鈕開關(guān)滑動(dòng)時(shí)帶有很炫的動(dòng)畫和漸變效果的代碼,本段代碼適應(yīng)于所有網(wǎng)頁(yè)使用,有興趣的朋友們可以前來(lái)下載使用2015-10-15