css3 switch开关

效果图
在这里插入图片描述
在这里插入图片描述
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    #mark-switch-inpt {
        display: none;
    }
    #mark-switch-inpt+label {
        display: inline-block;
        box-sizing: border-box;
        height: 22px;
        min-width: 44px;
        line-height: 20px;
        vertical-align: middle;
        border-radius: 100px;
        border: 1px solid transparent;
        background-color: #97C5FF;
        cursor: pointer;
        -webkit-transition: all 0.36s;
        transition: all 0.36s;
        position: relative;
    }
    #mark-switch-inpt:checked+label {
        background-color: #97C5FF;
    }
    #mark-switch-inpt+label::before {
        content: "";
        display: block;
        width: 18px;
        height: 18px;
        position: absolute;
        left: 1px;
        top: 1px;
        border-radius: 18px;
        background-color: #fff;
        cursor: pointer;
        transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
        -webkit-transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
        -webkit-box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
        box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
    }
    #mark-switch-inpt:checked+label::before {
        left: 23px;
        transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
        -webkit-transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
    }
    #mark-switch-inpt+label::after {
        content: "关";
        position: absolute;
        left: 24px;
        font-size: 12px;
        color: #fff;
        top: 0px;
        line-height: 20px;
        height: 20px;
    }
    #mark-switch-inpt:checked+label::after {
        content: "开";
        left: 5px;
        top: 0px;
        line-height: 20px;
        height: 20px;
    }
    </style>
</head>
<body>
    <input type="checkbox" id="mark-switch-inpt" />
    <label for="mark-switch-inpt"></label>
</body>
</html>

你可能感兴趣的:(css)