<div class="icon">
<svg width="100%" viewBox="0 0 24 24">
<path d="M4,4H20A2,2 0 0,1 22,6V18A2,2 0 0,1 20,20H4C2.89,20 2,19.1 2,18V6C2,4.89 2.89,4 4,4M12,11L20,6H4L12,11M4,18H20V8.37L12,13.36L4,8.37V18Z"></path>
</svg>
</div>
<div class="box">
<div class="toggle" id="increase">
<input type="checkbox">
<span class="button"></span>
<span class="label">+</span>
</div>
<div class="toggle" id="decrease">
<input type="checkbox" checked>
<span class="button"></span>
<span class="label">–</span>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=Gochi+Hand');
@import url(https://fonts.googleapis.com/css?family=Lato:700);
/* the cool stuff */
.icon {
--number-var: 23;
}
.icon::before {
counter-reset: number var(--number-var);
content: counter(number);
}
/* the pretty stuff */
body {
height: 100vh;
background-color: #000;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
font-family: 'Gochi Hand', cursive;
color: #fff;
}
.icon {
position: relative;
background-color: #fff;
fill: #555;
padding: 1.2rem;
border-radius: 50%;
width: 100px;
height: 100px;
}
.icon::before {
position: absolute;
width: 35px;
height: 35px;
background-color: #9a59c2;
border-radius: 50%;
line-height: 1;
box-sizing: border-box;
padding: 0.6rem; /* optical adjustment */
text-align: center;
top: 0;
right: -1%;
}
.box {
display: flex;
justify-content: center;
align-items: center;
min-width: 80vw;
margin: 20px;
font-family: 'Lato', sans-serif;
}
.toggle {
margin: 4px;
display: inline-block;
}
.toggle {
box-shadow: inset 0 0 35px 5px rgba(0, 0, 0, 0.25), inset 0 2px 1px 1px rgba(255, 255, 255, 0.9), inset 0 -2px 1px 0 rgba(0, 0, 0, 0.25);
border-radius: 8px;
background: #ccd0d4;
position: relative;
height: 100px;
width: 100px;
}
.toggle:before {
box-shadow: 0 0 17.5px 8.75px #fff;
border-radius: 118.3px;
background: #fff;
position: absolute;
margin-left: -50.4px;
margin-top: -50.4px;
opacity: 0.2;
content: "";
height: 100.8px;
width: 100.8px;
left: 50%;
top: 50%;
}
.toggle .button {
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
filter: blur(1px);
transition: all 300ms cubic-bezier(0.23, 1, 0.32, 1);
box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.5), inset 0 -3px 4px -1px rgba(0, 0, 0, 0.2), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 3px 4px -1px rgba(255, 255, 255, 0.2), inset 0 0 5px 1px rgba(255, 255, 255, 0.8), inset 0 20px 30px 0 rgba(255, 255, 255, 0.2);
border-radius: 96.32px;
position: absolute;
background: #ccd0d4;
display: block;
height: 80px;
width: 80px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.toggle .label {
transition: color 300ms ease-out;
text-shadow: 1px 1px 3px #ccd0d4, 0 0 0 rgba(0, 0, 0, 0.8), 1px 1px 4px #fff;
text-align: center;
position: absolute;
font-weight: 700;
font-size: 42px;
opacity: 0.9;
height: 100%;
width: 100%;
color: rgba(0, 0, 0, 0.4);
display: flex;
align-items: center;
justify-content: center;
}
.toggle input {
opacity: 0;
position: absolute;
cursor: pointer;
z-index: 1;
height: 100%;
width: 100%;
left: 0;
top: 0;
}
.toggle input:active ~ .button {
box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.4), inset 0 -8px 30px 1px rgba(255, 255, 255, 0.9), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 8px 25px 0 rgba(0, 0, 0, 0.4), inset 0 0 10px 1px rgba(255, 255, 255, 0.6);
}
.toggle input:active ~ .label {
font-size: 40px;
color: rgba(0, 0, 0, 0.45);
}
.toggle input:checked ~ .button {
box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.4), inset 0 -8px 25px -1px rgba(255, 255, 255, 0.9), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 8px 20px 0 rgba(0, 0, 0, 0.2), inset 0 0 5px 1px rgba(255, 255, 255, 0.6);
}
.toggle input:checked ~ .label {
font-size: 40px;
color: rgba(0, 0, 0, 0.4);
}
View Compiled
let styles = getComputedStyle(document.querySelector('.icon'));
let increaseValue = Number(styles.getPropertyValue('--number-var')) + 1;
let decreaseValue = Number(styles.getPropertyValue('--number-var')) - 1;
document.getElementById('increase').addEventListener('click', function(e){
document.querySelector('.icon').style.setProperty('--number-var', increaseValue++)
})
document.getElementById('decrease').addEventListener('click', function(e){
document.querySelector('.icon').style.setProperty('--number-var', decreaseValue--)
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.