h1.intro [CSS] 3D Switcher Vll Plus
small click to toggle
.box
input#io.Switcher__checkbox.sr-only(type="checkbox" checked)
label.Switcher(for="io")
.Switcher__trigger(data-value="SALE")
.Switcher__trigger(data-value="RENT")
blockquote.info
| inspired from
a(href="https://dribbble.com/shots/2286747-Switcher-Vll-Plus") Switcher Vll Plus
| by
a(href="https://dribbble.com/Volorf") Oleg Frolov
View Compiled
$c-white: #fff;
$c-black: #000;
$c-theme: #00a8ff;
.Switcher {
position: relative;
display: flex;
border-radius: 5em;
box-shadow: inset 0 0 0 1px;
overflow: hidden;
cursor: pointer;
animation: r-n .5s;
user-select: none;
font-size: 3vmin;
will-change: transform;
.Switcher__checkbox:checked + & {
animation-name: r-p;
}
@keyframes r-p {
50% { transform: rotateY(45deg); }
}
@keyframes r-n {
50% { transform: rotateY(-45deg); }
}
// indicator
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 200%;
border-radius: inherit;
background-color: $c-white;
transform: translateX(-75%);
transition: transform .5s ease-in-out;
.Switcher__checkbox:checked + & {
transform: translateX(25%);
}
}
}
.Switcher__trigger {
position: relative;
z-index: 1;
padding: 1em 5em;
&::after {
content: attr(data-value);
}
&::before {
--i: var(--x);
content: attr(data-value);
position: absolute;
color: $c-theme;
transition: opacity .3s;
opacity: calc((var(--i) + 1) / 2);
transition-delay: calc(.3s * (var(--i) - 1) / -2);
.Switcher__checkbox:checked + .Switcher & {
--i: calc(var(--x) * -1);
}
}
&:nth-of-type(1)::before {
--x: 1;
}
&:nth-of-type(2)::before {
--x: -1;
}
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
.box {
display: flex;
flex: 1;
justify-content: center;
align-items: center;
flex-wrap: wrap;
overflow: hidden;
perspective: 750px;
}
/// reset
*,
*::before,
*::after {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
min-height: 100%;
margin: 0;
line-height: 1.4;
color: $c-white;
background-color: $c-theme;
}
.intro {
width: 90%;
max-width: 50rem;
padding-top: .5em;
padding-bottom: 1rem;
margin: 0 auto 1em;
font-size: calc(1rem + 2vmin);
text-transform: capitalize;
text-align: center;
font-family: serif;
small {
display: block;
text-align: right;
opacity: .5;
font-style: italic;
text-transform: none;
border-top: 1px dashed rgba($c-white, .75);
}
}
.info {
margin: 0;
padding: 1em;
font-size: .9em;
font-style: italic;
font-family: serif;
text-align: right;
opacity: .75;
a {
color: inherit;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.