css3实现checkbo美化

<!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>
   * {
    box-sizing: border-box;
}
html,
body {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #1abc9c;
    font-family: 'Roboto', sans-serif;
}
.list {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    margin: 0;
    padding: 0;
    width: 80%;
    max-width: 500px;
    background-color: #fff;
    border-radius: 6px;
    box-shadow: 10px 10px 0 0 rgba(0, 0, 0, 0.2);
    list-style: none;
    overflow: hidden;
}
.list .list-item {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid #ecf0f1;
    position: relative;
}
.list .list-item:last-child {
    border: 0;
}
.hidden-box {
    position: absolute;
    top: -9999px;
    left: -9999px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    opacity: 0;
}
.check--label {
    font-size: 20px;
    margin: 0;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-flex-wrap: nowrap;
    -ms-flex-wrap: nowrap;
    flex-wrap: nowrap;
    -webkit-box-pack: start;
    -webkit-justify-content: flex-start;
    -ms-flex-pack: start;
    justify-content: flex-start;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
}
.check--label-box {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-align-self: center;
    -ms-flex-item-align: center;
    align-self: center;
    position: relative;
    height: 20px;
    width: 20px;
    margin: 0 20px;
    border: 2px solid #3498db;
    border-radius: 2px;
    cursor: pointer;
}
.check--label-text {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-align-self: center;
    -ms-flex-item-align: center;
    align-self: center;
    position: relative;
    cursor: pointer;
    padding: 20px;
    border-left: 1px solid #ecf0f1;
}
.check--label-text:after {
    content: '';
    display: block;
    width: 0%;
    height: 2px;
    background-color: #000;
    position: absolute;
    top: 50%;
    left: 7.5%;
    /* -webkit-transform: translateY(-50%);
    transform: translateY(-50%);*/
    -webkit-transition: width 100ms ease-in-out;
    transition: width 100ms ease-in-out; 
}
.hidden-box:checked + .check--label {
    background-color:red;
}
.hidden-box:checked + .check--label .check--label-box {
    color: yellow
}
.hidden-box:checked + .check--label .check--label-box:after {
    content: '';
    display: block;
    position: absolute;
    top: -1px;
    left: 4px;
    width: 6px;
    height: 12px;
    border: solid #000;
    border-width: 0 2px 2px 0;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}
.hidden-box:checked + .check--label .check--label-text:after {
    width: 85%;
}
</style>
<body>
    <ul class="list">
        <li class="list-item">
            <input type="checkbox" class="hidden-box" id="first" checked/>
            <label for="first" class="check--label">
                <span class="check--label-box"></span>
                <span class="check--label-text">First Checkbox</span>
            </label>
        </li>
        <li class="list-item">
            <input type="checkbox" class="hidden-box" id="second" />
            <label for="second" class="check--label">
                <span class="check--label-box"></span>
                <span class="check--label-text">Second Checkbox</span>
            </label>
        </li>
        <li class="list-item">
            <input type="checkbox" class="hidden-box" id="third" />
            <label for="third" class="check--label">
                <span class="check--label-box"></span>
                <span class="check--label-text">Third Checkbox</span>
            </label>
        </li>
    </ul>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值