JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<form class="back">
<span class="fa fa-search searchicon" aria-hidden="true">
</span>
<input type="text" name="search" class="extand ">
</form>
CSS
.back{
padding: 0.5%;
background: #10314c;
}
.searchicon {
float: left;
margin-top: -20px;
position: relative;
top: 26px;
left: 8px;
color: white;
z-index: 2;
}
.extand {
width: 2.4%;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background: #10314c;
background-position: 10px 10px;
background-repeat: no-repeat;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
.extand-now {
width: 50%;
}
JavaScript
// for the icon
$(".searchicon").click(function() {
$('.extand').toggleClass('extand-now');
});
// for the input
$(".extand").click(function() {
$('.extand').toggleClass('extand-now');
});