<a href="https://youtu.be/FX6i5e1sPqM" target="_blank" data-keyframers-credit style="color: #FFF"></a>
<script src="https://codepen.io/shshaw/pen/QmZYMG.js"></script>
<label class="search">
<div class="one">
<div class="two">
<div class="three">
<input type="search" class="four" placeholder="@Keyframers Search" />
</div>
<div class="stick"></div>
</div>
</div>
</label>
$border-width: 0.1em;
$circle-width: 1em;
$search-width: 15em;
$duration: 0.6s;
*,
*:before,
*:after {
transition: transform $duration cubic-bezier(.6,0,.4,1);
}
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: inherit;
opacity: 0.6;
}
::-moz-placeholder { /* Firefox 19+ */
color: inherit;
opacity: 0.6;
}
:-ms-input-placeholder { /* IE 10+ */
color: inherit;
opacity: 0.6;
}
:-moz-placeholder { /* Firefox 18- */
color: inherit;
opacity: 0.6;
}
.search {
overflow: hidden;
padding: 0 0 1.25em;
opacity: 0.7;
cursor: pointer;
transition-property: opacity;
transition-duration: .3s;
&:hover, &:focus-within {
opacity: 1;
}
}
.one {
font-size: 5vw;
margin-top: 1rem;
width: calc(#{$search-width} - #{$circle-width * 2});
height: $circle-width * 2;
z-index: 2;
}
.two {
width: calc(100% - #{$circle-width});
height: 100%;
position: absolute;
top: 0;
left: $circle-width;
}
.one:before,
.two:before {
content: "";
position: absolute;
height: 100%;
width: $circle-width;
border: $border-width solid white;
&:hover {
background-color: #fff;
}
}
.one:before {
left: 0;
border-right: none;
border-radius: $circle-width 0 0 $circle-width;
}
.two:before {
right: 0;
border-left: none;
border-radius: 0 $circle-width $circle-width 0;
}
.three {
height: 100%;
width: calc(100% - #{$circle-width});
overflow: hidden;
}
// this is the search input!!!
input[type="search"] {
display: block;
width: 100%;
height: 100%;
border: $border-width solid;
border-left: none;
border-right: none;
background: transparent;
color: white;
font: inherit;
&,
&:focus {
outline: none;
}
}
.stick {
position: absolute;
height: $circle-width;
width: $border-width;
right: $circle-width;
top: 50%;
transform: translate(0%, -50%);
&:before,
&:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #fff;
}
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
}
// -------------------------------
.one {
transform: translateX(50%) translateX(-#{$circle-width});
}
.two {
transform: translateX(-100%) translateX(#{$circle-width});
}
.three {
transform: translateX(100%);
}
.four {
transform: translateX(-100%);
}
.stick {
&:before,
&:after {
transform: rotate(-45deg) translateY(150%);
}
}
// -------------------------------
.search:after {
content: '';
position: absolute;
top: 1.25em;
left: .25em;
right: .25em;
bottom: 1.5em;
z-index: 0;
border: solid 0.25em turquoise;
box-sizing: content-box;
opacity: 0;
transition-duration: #{$duration / 3};
transition-property: opacity;
border-radius: 3em;
}
// -------------------------------
.search:focus-within {
&:after {
opacity: 1;
transition-delay: $duration;
}
.one,
.two,
.three,
.four {
transform: translateX(0);
}
.stick {
pointer-events: auto;
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
}
}
body {
transition-property: background-color;
&:focus-within {
background-color: #53ADFF;
}
}
// -------------------------------
*,
*:before,
*:after {
position: relative;
box-sizing: border-box;
}
body,
html {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
background-color: #5361ff;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
View Compiled
document.querySelector('.stick').addEventListener('click',()=>{
document.querySelector('.four').value = '';
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.