<div class="body-container">
<h1>Search bar</h1>
<div class="search-bar">
<span class="search-icon"></span>
<form class="search" action="">
<input class="search" type="text" placeholder="Search"/>
<button type="submit" class="btn">Go</button>
</form>
</div>
</div>
// Colors
$color_main: #ccf;
$color_background: navy;
// Fonts
@import url('https://fonts.googleapis.com/css?family=Roboto');
div.search-bar {
display: flex;
}
form.search {
display: inline-flex;
max-width: 0;
overflow: hidden;
transition: 0.5s ease all;
&.open {
max-width: 40em;
}
}
input.search {
margin: 0 0.4em;
border: none;
background: none;
border-bottom: 1px solid $color_main;
color: inherit;
font-family: inherit;
font-size: 1.5em;
min-width: 10em;
width: 70vw;
max-width: 20em;
&:focus {
outline: none;
}
}
.btn {
display: inline-block;
background: none;
color: $color_main;
border: 1px solid $color_main;
border-radius: 0.25em;
font-size: 1.2em;
min-width: 3em;
&:focus {
outline: none;
color: $color_background;
background: $color_main;
}
}
span.search-icon {
display: inline-block;
position: relative;
width: 2em;
height: 2em;
cursor: pointer;
&:after {
content: '';
display: inline-block;
position: absolute;
width: 50%;
height: 50%;
border-radius: 50%;
top: 0;
right: 0;
border: 0.25em solid $color_main;
}
&:before {
content: '';
display: inline-block;
position: absolute;
height: 0.25em;
width: 42%;
background: $color_main;
top: 50%;
transform-origin: 100% 50%;
transform: rotateZ(-45deg);
}
}
// Stuff here is for centering
div.body-container {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
body {
margin: 0;
color: $color_main;
background: $color_background;
font-family: 'Roboto', sans-serif;
}
View Compiled
var icon = $('.search-icon');
var form = $('form.search');
icon.click(function() {
form.toggleClass('open');
if (form.hasClass('open')) {
form.children('input.search').focus();
}
});
This Pen doesn't use any external CSS resources.