<form action="" class="search-form">
<div class="search-box">
<input class="search-input" type="text" placeholder="Search..."/>
<button class="search-button"><span></span></button>
</div>
</form>
@import url(https://fonts.googleapis.com/css?family=Roboto:300);
$indigo: #536dc8;
$danube: #6191d1;
$white: #fff;
$bermuda: #77D7B9;
* {
box-sizing: border-box;
}
@mixin center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
body {
background-image: linear-gradient(to left, $danube, $indigo);
height: 100vh;
font-smoothing: antialiased;
}
@keyframes roll {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
50% {
transform: translate(-80px, -50%) rotate(-10deg);
}
100% {
transform: translate(130px, -50%) rotate(360deg);
}
}
@keyframes roll-back {
0% {
transform: translate(130px, -50%) rotate(360deg);
}
100% {
transform: translate(-50%, -50%) rotate(0deg);
}
}
@keyframes expand {
0% {
width: 60px;
height: 60px;
opacity: 0;
}
50% {
opacity: 1;
width: 80px;
height: 80px;
}
100% {
width: 400px;
height: 80px;
opacity: 1;
}
}
@keyframes collapse {
0% {
width: 400px;
height: 80px;
opacity: 1;
}
50% {
opacity: 1;
width: 80px;
height: 80px;
}
100% {
width: 60px;
height: 60px;
opacity: 0;
}
}
.search-form {
@include center;
width: 400px;
height: 80px;
text-align: center;
backface-visibility: hidden;
.search-input {
border: 0;
padding: 0 20px;
width: 0;
height: 0;
border-radius: 50px;
background-color: $danube;
font-size: 1.6em;
color: $white;
font-family: 'Roboto', sans-serif;
.animate & {
animation: collapse 0.3s 0.4s both ease-in;
}
.focus & {
animation: expand 0.3s both ease-in;
}
&::input-placeholder {
color: $white;
}
&:placeholder {
/* Firefox 18- */
color: $white;
}
&::placeholder {
/* Firefox 19+ */
color: $white;
}
&:input-placeholder {
color: $white;
}
&:focus {
outline: none;
}
}
.search-button {
@include center;
width: 60px;
height: 60px;
background-color: $bermuda;
border: 0;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.4);
backface-visibility: hidden;
.animate & {
animation: roll-back 0.2s both ease-in;
}
.focus & {
animation: roll 0.4s 0.9s both ease-in;
}
&:focus {
outline: none;
}
span {
width: 25px;
height: 25px;
border-radius: 50%;
border: 4px solid $white;
display: block;
position: absolute;
top: 13px;
left: 14px;
&:after {
content: '';
width: 4px;
height: 15px;
background-color: $white;
position: absolute;
transform: rotate(-45deg);
top: 12px;
left: 18px;
}
}
}
}
View Compiled
$('.search-button').on('click', function(e) {
e.preventDefault();
$('body').addClass('animate').toggleClass('focus');
});
This Pen doesn't use any external CSS resources.