css实现checkbox美化

代码语言:html

所属分类:表单美化

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Pure CSS Styled Checkboxes</title>

    <style>
@import url('https://fonts.googleapis.com/css?family=Big+Shoulders+Text&display=swap');

        html {
            font-size: 62.5%;
        }

        * {
            box-sizing: border-box;
        }

        .wrapper {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 100vw;
            height: 100vh;
            font-family: 'Big Shoulders Text', cursive;
            font-size: 1.6rem;
        }

        /* ALL TOGGLES */
        .toggle {
            height: 4rem;
        }
        .toggle input[type=checkbox] {
            display: none;
        }
        .toggle span {
            /* space between label and toggle */
            padding-left: .5rem;
        }
        .toggle label span::before,
        .toggle label span::after {
            position: absolute;
        }
        .toggle label span::before {
            /* off label text */
            content: 'OFF';
        }
        .toggle input[type=checkbox]:checked + label span::before {
            /* on label text */
            content: 'ON';
        }

        /* STYLE 1 */
        .style1 label {
            color: #cccfcd;
            display: block;
            text-transform: uppercase;
            font-size: 2rem;
            font-weight: 300;
            cursor: pointer;
            transition: all .2s ease;
            position: relative;
            line-height: 2rem;
        }
        .style1 label::before {
            content: '';
            position: absolute;
            left: 0;
            -webkit-transform: translateX(-3.8rem);
            transform: translateX(-3.8rem);
            width: 3rem;
            height: 2rem;
            border-radius: 1rem;
            background-color: #cccfcd;
            transition: all .2s ease;
            box-shadow: inset -1px -1px 5px 3px rgba(0,0,0,.2);
            border: 1px solid #c4c7c3;
        }
        .style1 label::after {
            content: '';
            position: absolute;
            left: 0;
            -webkit-transform: translate(-3.6rem, .15rem);
            transform: translate(-3.6rem, .15rem);
            width: 1.7rem;
            height: 1.7rem;
            border-radius: 1rem;
            background-color: #FFFFFF;
            box-shadow: 1px 1px 1px 1px rgba(0,0,0,.1);
            transition: all .2s ease;
            border: 1px solid #c4c7c3;
        }
        .style1 input[type=checkbox]:checked + label {
            color: #18c953;
        }
        .style1 input[type=checkbox]:checked + label::before {
            background-color: #18c953;
        }
        .style1 input[type=checkbox]:checked + label::after {
            -webkit-transform: translate(-2.7rem, .15rem);
            transform: translate(-2.7rem, .15rem);
        }

        /* STYLE 2 */
        .style2 label {
            color: #cccfcd;
            display: block;
            text-transform: uppercase;
            font-size: 2rem;
            font-weight: 300;
            cursor: pointer;
            transition: all .2s ease;
            position: relative;
            line-height: 2rem;
        }
        .style2 label::before {
            content: '';
            position: absolute;
            left: 0;
            -webkit-transform: translate(-3.8rem, .4rem);
            transform: translate(-3.8rem, .4rem);
            width: 3rem;
            height: 1.2rem;
            border-radius: .4rem;
            background-color: #cccfcd;
            transition: all .2s ease;
            box-shadow: inset -1px -1px 5px 3px rgba(0,0,0,.2);
            border: 1px solid #c4c7c3;
        }
        .style2 label::after {
            content: '';
            position: absolute;
            left: 0;
            -webkit-transform: translate(-3.9rem, .05rem);
            transform: translate(-3.9rem, .05rem);
            width: 1.8rem;
            height: 1.8rem;
            border-radius: 1rem;
            background-color: #FFFFFF;
            box-shadow: 1px 1px 2px 1px rgba(0,0,0,.1);
            transition: all .2s ease;
            border: 1px solid #c4c7c3;
        }
        .style2 input[type=checkbox]:checked + label {
            color: #18c953;
        }
        .style2 input[type=checkbox]:checked + label::before {
            background-color: #18c953;
        }
        .styl.........完整代码请登录后点击上方下载按钮下载查看

网友评论0