【CSS】使用原生html+css实现酷炫多选框

效果展示

在这里插入图片描述

完整代码

html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* @import url('./index.css'); */
    @import url('./index_mine.css');
</style>

<body>

    <div class="container">
        <div class="components">
            <div class="checkbox">
                <div class="checkbox__1">
                    <input id="checkbox-1" type="checkbox">
                    <label for="checkbox-1"></label>
                </div>
                <div class="checkbox__2">
                    <input id="checkbox-2" type="checkbox" checked>
                    <label for="checkbox-2"></label>
                </div>
            </div>
        </div>
    </div>

</body>
</html>

css

:root {
    --primary-light: #8abdff;
    --primary: #6d5dfc;
    --primary-dark: #5b0eeb;

    --white: #FFFFFF;
    --greyLight-1: #E4EBF5;
    --greyLight-2: #c8d0e7;
    --greyLight-3: #bec8e4;
    --greyDark: #9baacf;
    --shadow: .3rem .3rem .6rem var(--greyLight-2),
        -.2rem -.2rem .5rem var(--white);
}

*,
*::before,
*::after {
    padding: 0;
    margin: 0;
    box-sizing: inherit;
}

html {
    box-sizing: border-box;
    background-color: var(--greyLight-1);
    overflow-y: scroll;
    font-size: 62.5%;
}


.container {
    min-height: 100vh;
    background-color: var(--greyLight-1);
    display: flex;
    justify-content: center;
    align-items: center;
}
.components {
    width: 75rem;
    height: 40rem;
    border-radius: 3rem;
    display: grid;
    box-shadow: .8rem .8rem 1.4rem var(--greyLight-2),
        -.2rem -.2rem 1.8rem var(--white);
    padding: 4rem;
    grid-template-columns: 17.6rem 19rem 20.4rem;
    grid-template-rows: repeat(autofit, min-content);
    grid-column-gap: 5rem;
    grid-row-gap: 2.5rem;
    align-items: center;
}
.checkbox{
    grid-column:1 / 2;
    display: grid;
    grid-template-columns: repeat(2,6rem);
    grid-gap: 3rem;
    justify-content: center;
}

.checkbox input{
    display: none;
}

.checkbox__1,
.checkbox__2{
    width: 6rem;
    display: flex;
    justify-content: center;
}

.checkbox__1 label,
.checkbox__2 label{
    position: relative;
    width: 2.8rem;
    height: 2.8rem;
    height: 3.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: .5rem;
    background: rgba(255, 255, 255, 0);
    box-shadow: var(--shadow);
    cursor: pointer;
}

.checkbox__1 label::before,
.checkbox__2 label::before{
    content: '';
    position: absolute;
    left: 40%;
    top: 19%;
    width: 27%;
    height: 49%;
    border: .3rem solid var(--greyDark);
    transform: rotate(45deg);
    border-top: 0;
    border-left: 0;
    transition: border .3s ease;
}

.checkbox__1 input:hover~label::before,
.checkbox__2 input:hover~label::before{
    border: .3rem solid var(--primary);
    border-top: 0;
    border-left: 0;
}

.checkbox__1 input:checked~label,
.checkbox__2 input:checked~label {
    box-shadow: inset 0.2rem 0.2rem 0.5rem var(--greyLight-2), inset -0.2rem -0.2rem 0.5rem var(--white)
}

.checkbox__1 input:checked~label::before,
.checkbox__2 input:checked~label::before{
    border: .3rem solid var(--primary);
    border-top: 0;
    border-left: 0;
}

大功告成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值