第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

通過css3實(shí)現(xiàn)開關(guān)選擇按鈕

標(biāo)簽:
Html/CSS Html5 CSS3

通过css属性实现如图所示按钮
图片描述
要点:通过checkbox选中与否的状态与兄弟选择器实现相关功能
1.设置开关大小并设置定位方式为relative

.swift-btn {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 25px;
}

2.设置checkbox属性,并设置为不可见状态

.swift-btn input[type='checkbox'] {
    position: absolute;
    width: 50px;
    height: 25px;
    opacity: 0;
    z-index: 9;
    outline: none;
}

3.设置按钮样式,通过伪类元素实现,并添加过渡动画

.swift-btn > label{
    position: absolute;
    display: inline-block;
    width: 50px;
    height: 25px;
    border-radius: 25px;
    border: 1px solid #ddd;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
}
.swift-btn > label:before {
    content: '';
    position: absolute;
    display: inline-block;
    left: 40px;
    width: 25px;
    height: 25px;
    border-radius: 20px;
    line-height: 25px;
    text-indent: -1px;
}
.swift-btn > label:after {
    content: '';
    position: absolute;
    display: inline-block;
    width: 24px;
    height: 24px;
    left: 0;
    top: 1px;
    border-radius: 1px;
    box-shadow:2px 0px 1px #ddd;
    border-radius: 15px;
    background-color: #fff;
    transition: left 0.3s ease;
    -webkit-transition: left 0.3s ease;
    -moz-transition: left 0.3s ease;
}

4.设置input选中后的样式

.swift-btn input[type='checkbox']:checked + label{
    border: 1px solid #000;
    background-color: #000;
}
.swift-btn input[type='checkbox']:checked + label::before {
    display: inline-block;
    color: #fff;
    text-indent: -25px;
}
.swift-btn input[type='checkbox']:checked + label::after {
    left: 26px;
    top: 1px;
    width: 24px;
    height: 24px;
    border: 0;
    box-shadow: none;
    box-sizing: content-box;
}

完整代码示例

<!DOCTYPE html>
<html>
<meta charset='utf-8'>

<style>
.swift-btn {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 25px;
}
.swift-btn input[type='checkbox'] {
    position: absolute;
    width: 50px;
    height: 25px;
    opacity: 0;
    z-index: 9;
    outline: none;
}
.swift-btn > label{
    position: absolute;
    display: inline-block;
    width: 50px;
    height: 25px;
    border-radius: 25px;
    border: 1px solid #ddd;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
}
.swift-btn > label:before {
    content: '';
    position: absolute;
    display: inline-block;
    left: 40px;
    width: 25px;
    height: 25px;
    border-radius: 20px;
    line-height: 25px;
    text-indent: -1px;
}
.swift-btn > label:after {
    content: '';
    position: absolute;
    display: inline-block;
    width: 24px;
    height: 24px;
    left: 0;
    top: 1px;
    border-radius: 1px;
    box-shadow:2px 0px 1px #ddd;
    border-radius: 15px;
    background-color: #fff;
    transition: left 0.3s ease;
    -webkit-transition: left 0.3s ease;
    -moz-transition: left 0.3s ease;
}
.swift-btn input[type='checkbox']:checked + label{
    border: 1px solid #000;
    background-color: #000;
}
.swift-btn input[type='checkbox']:checked + label::before {
    display: inline-block;
    color: #fff;
    text-indent: -25px;
}
.swift-btn input[type='checkbox']:checked + label::after {
    left: 26px;
    top: 1px;
    width: 24px;
    height: 24px;
    border: 0;
    box-shadow: none;
    box-sizing: content-box;
}
</style>

<body>
<span class="add-item-status swift-btn">
    <input type="checkbox" name="" id='checkbox' />
    <label class="" for='checkbox'></label>
</span>
</body>
</html>

判断是否选中可通过判断chekbox选中状态来判断,如通过jQuery判断方法:
var status = $('#checkbox').is(':checked');

點(diǎn)擊查看更多內(nèi)容
24人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
PHP開發(fā)工程師
手記
粉絲
8
獲贊與收藏
282

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消