效果展示
完整代码
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;
}
大功告成!