<div class="search">
<input id='search-btn' type='checkbox'/>
<label for='search-btn'>显示搜索栏</label>
<input id='search-bar' type='text' placeholder='w3cplus.com'/>
</div>
$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;
$x: .5*($bar-w + $btn-r) - $btn-r;
$out-d: -3em;
$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;
align-items: center;
justify-content: center;
width: 100vw;
min-height: 100vh;
background: #252525
}
[id='search-btn'] {
position: absolute;
left: -100vh;
~ * {
--i: 0;
--j: calc(1 - var(--i));
transition: .65s;
}
&:checked ~ * {
--i: 1;
}
}
.search {
min-width: 400px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: row-reverse;
}
[for='search-btn'] {
--hsl: 0, 0%, 0%;
color: HSL(var(--hsl));
display: block;
overflow: hidden;
width: $btn-d;
height: $btn-d;
border-radius: 50%;
box-shadow: 0 0 1.5em rgba(#000, .4);
text-indent: -100vw;
cursor: pointer;
position: relative;
z-index: 1;
transform: translate(calc(var(--j)*#{-$x})) rotate(45deg);
$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));
background: hsl(calc(var(--j)*#{$h0} + var(--i)*#{$h1}),
calc(var(--j)*#{$s0} + var(--i)*#{$s1}),
calc(var(--j)*#{$l0} + var(--i)*#{$l1}));
&: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;
background: currentColor;
transform-origin: 100% 50%;
transform:
translate(calc(var(--j)*#{.25*$ico-d}))
scalex(calc(1 - var(--j)*.5));
}
&:after {
box-shadow: inset 0 0 0 $ico-w currentcolor, inset 0 0 0 calc(var(--i)*#{.5*$ico-d}) HSLA(var(--hsl), var(--i));
border-radius: calc(var(--j)*50%);
transform: translate(calc(var(--j)*#{-.25*$ico-d}))
scalex(calc(var(--j) + var(--i)*#{$ico-f}));
}
}
[id='search-bar'] {
border: none;
padding: 0 1em;
width: $bar-w;
height: $bar-h;
border-radius: $bar-r 0 0 $bar-r;
background: #3f324d;
color: #fff;
font: 1em century gothic, verdana, arial, sans-serif;
margin-right: -$btn-r;
padding: 0 calc(#{$btn-r} + 1em) 0 1em;
transform: translate(calc(var(--j)*#{$x}));
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 1.25em 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.