<input id='search-btn' type='checkbox'/>
<label for='search-btn'>Show search bar</label>
<input id='search-bar' type='text' placeholder='Search...'/>
$btn-d: 5em;
$btn-r: .5*$btn-d;
$bar-w: 4*$btn-d;
$bar-h: .65*$btn-d;
$bar-r: .5*$bar-h;
$bar-c: #ffeacc;
$out-d: -3em;
$x: .5*($bar-w + $btn-r) - $btn-r;
$ico-d: .5*$bar-h;
$ico-f: .125;
$ico-w: $ico-f*$ico-d;
*, :before, :after {
box-sizing: border-box;
margin: 0;
padding: 0;
font: inherit
}
html { overflow-x: hidden }
body {
display: flex;
flex-direction: row-reverse;
align-items: center;
justify-content: center;
margin: 0 auto;
min-width: 400px; min-height: 100vh;
background: #252525
}
[id='search-btn'] {
position: absolute;
left: -100vw;
~ * {
--i: 0;
--j: calc(1 - var(--i));
transition: .65s
}
&:checked ~ * { --i: 1 }
}
[for='search-btn'] {
$c0: #d9eb52; // green for collapsed state
$c1: #dd1d6a; // pink for expanded state
$h0: round(hue($c0)/1deg);
$s0: round(saturation($c0));
$l0: round(lightness($c0));
$h1: round(hue($c1)/1deg);
$s1: round(saturation($c1));
$l1: round(lightness($c1));
overflow: hidden;
position: relative;
z-index: 1;
width: $btn-d; height: $btn-d;
border-radius: 50%;
transform: translate(calc(var(--j)*#{-$x})) rotate(45deg);
box-shadow: 0 0 1.5em rgba(#000, .4);
background: hsl(calc(var(--j)*#{$h0} + var(--i)*#{$h1}),
calc(var(--j)*#{$s0} + var(--i)*#{$s1}),
calc(var(--j)*#{$l0} + var(--i)*#{$l1}));
--hsl: 0, 0%, 0%;
color: HSL(var(--hsl));
text-indent: -100vw;
cursor: pointer;
&:before, &:after {
position: absolute;
top: 50%; left: 50%;
margin: -.5*$ico-d;
width: $ico-d; height: $ico-d;
transition: inherit;
content: ''
}
&:before {
margin-top: -.4*$ico-w;
height: $ico-w;
transform-origin: 100% 50%;
transform: translate(calc(var(--j)*#{.25*$ico-d}))
scalex(calc(1 - var(--j)*.5));
background: currentcolor
}
&:after {
border-radius: calc(var(--j)*50%);
transform: translate(calc(var(--j)*#{-.25*$ico-d}))
scalex(calc(var(--j) + var(--i)*#{$ico-f}));
box-shadow: inset 0 0 0 $ico-w currentcolor,
inset 0 0 0 calc(var(--i)*#{.5*$ico-d}) HSLA(var(--hsl), var(--i))
}
}
[id='search-bar'] {
border: none;
margin-right: -$btn-r;
padding: 0 calc(#{$btn-r} + 1em) 0 1em;
width: $bar-w; height: $bar-h;
border-radius: $bar-r 0 0 $bar-r;
transform: translate(calc(var(--j)*#{$x}));
background: #3f324d;
color: #fff;
font: 1em century gothic, verdana, arial, sans-serif;
clip-path:
inset($out-d calc(var(--j)*#{$bar-w - $btn-r}) $out-d $out-d);
&::placeholder {
opacity: .5;
color: inherit;
font-size: .875em;
letter-spacing: 1px;
text-shadow: 0 0 1px, 0 0 2px
}
&:focus {
outline: none;
box-shadow: 0 0 1.5em $bar-c, 0 .75em 1.5em rgba(#000, .2);
background: $bar-c;
color: #000;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.