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

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

css3實(shí)現(xiàn)radio選擇效果

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

该手记通过简单教程,实现如图所示的radio单选样式效果
图

html结构,div中包含一个radio单选框与一个指向该单选框的label标签

<div class='radio-check'>
    <input type='radio' name='test' id='test1'/>
    <label for='test1' class>苹果</label>
</div>

初始化相关结构样式,设置div定位为relative,radio与label为absolute定位

.radio-check {
    position: relative;
    height: 35px;
}
.radio-check > input {
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height:20px;
    opacity: 0;
}
.radio-check > label {
    position: absolute;
    left: 30px;
    line-height: 20px;
    top: 0px;
}

通过伪类::before与::after,实现选中效果

初始化before与after状态

.radio-check > label:before {
    content: '';
    position: absolute;
    left: -30px;
    top: 0px;
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ddd;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
}
.radio-check > label:after {
    content: '';
    position: absolute;
    left: -30px;
    top: 0px;
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 6px;
    margin-left: 6px;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
}

利用radio选中状态的:checked伪类选择器与兄弟选择器,实现选中效果

.radio-check input[type='radio']:checked + label:before {
    border-color: #4cd764;
}
.radio-check input[type='radio']:checked + label:after {
    background: #4cd764;
}

整体代码示例

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport"/>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
</head>
<style>
.radio-check {
    position: relative;
    height: 35px;
}
.radio-check > input {
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height:20px;
    opacity: 0;
}
.radio-check > label {
    position: absolute;
    left: 30px;
    line-height: 20px;
    top: 0px;
}
.radio-check > label:before {
    content: '';
    position: absolute;
    left: -30px;
    top: 0px;
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ddd;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
}
.radio-check > label:after {
    content: '';
    position: absolute;
    left: -30px;
    top: 0px;
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 6px;
    margin-left: 6px;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
}
.radio-check input[type='radio']:checked + label:before {
    border-color: #4cd764;
}
.radio-check input[type='radio']:checked + label:after {
    background: #4cd764;
}

</style>
<body>
<div class='radio-check'>
    <input type='radio' name='test' id='test1'/>
    <label for='test1' class>苹果</label>
</div>
<div class='radio-check'>
    <input type='radio' name='test' id='test2'/>
    <label for='test2' class>橘子</label>
</div>
<div class='radio-check'>
    <input type='radio' name='test' id='test3'/>
    <label for='test3' class>梨</label>
</div>
<div class='radio-check'>
    <input type='radio' name='test' id='test4'/>
    <label for='test4' class>香蕉</label>
</div>
<div class='radio-check'>
    <input type='radio' name='test' id='test5'/>
    <label for='test5' class>菠萝</label>
</div>
</body>
</html>

其他相关手记:
通过css3实现开关选择按钮
通过css3实现checkbox选择样式

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

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

評(píng)論

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

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

100積分直接送

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

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

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

購課補(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
提交
取消