<form class="search">
<div class="search__wrapper">
<input type="text" name="" placeholder="Search for..." class="search__field">
<button type="submit" class="fa fa-search search__icon"></button>
</div>
</form>
@icon-size: 50px;
@main-color: #e9f1f4;
// STYLE TO WRAP UP THE DEMO
.search {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
* {
outline: none;
box-sizing: border-box;
}
}
// SEARCH FIELD
.search__wrapper {
position: relative;
}
.search__field {
width: @icon-size;
height: @icon-size;
color: transparent;
font-family: Lato, sans-serif;
font-size: 1.35em;
padding: .35em (@icon-size) .35em 0;
border: 1px solid transparent;
border-radius: 0;
cursor: pointer;
transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
&:focus {
border-bottom-color: #ccc;
width: 50vw;
color: #2b2b2b;
cursor: default;
~ .search__icon {
background-color: transparent;
cursor: pointer;
pointer-events: auto;
}
}
}
.search__icon {
position: absolute;
top: 0;
right: 0;
background-color: @main-color;
width: @icon-size;
height: @icon-size;
font-size: 1.35em;
text-align: center;
border-color: transparent;
border-radius: 50%;
pointer-events: none;
display: inline-block;
transition: background-color 0.2s ease-in-out;
transition: background-color 0.2s ease-in-out;
}
// FIELD LABELING
.search__field::input-placeholder {
position: relative;
top: 0;
left: 0;
transition-property: top, color;
transition-property: top, color;
transition-duration: .1s;
transition-duration: .1s;
transform: translateZ(0);
transform: translateZ(0);
backface-visibility: hidden;
backface-visibility: hidden;
perspective: 1000;
perspective: 1000;
}
.search__field:placeholder {
position: relative;
top: 0;
left: 0;
transition-property: top, color;
transition-property: top, color;
transition-duration: .1s;
transition-duration: .1s;
transform: translateZ(0);
transform: translateZ(0);
backface-visibility: hidden;
backface-visibility: hidden;
perspective: 1000;
perspective: 1000;
}
.search__field::placeholder {
position: relative;
top: 0;
left: 0;
transition-property: top, color;
transition-property: top, color;
transition-duration: .1s;
transition-duration: .1s;
transform: translateZ(0);
transform: translateZ(0);
backface-visibility: hidden;
backface-visibility: hidden;
perspective: 1000;
perspective: 1000;
}
.search__field:input-placeholder {
position: relative;
top: 0;
left: 0;
transition-property: top, color;
transition-property: top, color;
transition-duration: .1s;
transition-duration: .1s;
transform: translateZ(0);
transform: translateZ(0);
backface-visibility: hidden;
backface-visibility: hidden;
perspective: 1000;
perspective: 1000;
}
.search__field::input-placeholder[style*=hidden] {
color: darken(@main-color, 30%);
font-size: .65em;
font-weight: normal;
top: -(round(@icon-size / 2.5));
opacity: 1;
visibility: visible !important;
}
.search__field:placeholder[style*=hidden] {
color: darken(@main-color, 30%);
font-size: .65em;
font-weight: normal;
top: -(round(@icon-size / 2.5));
opacity: 1;
visibility: visible !important;
}
.search__field::placeholder[style*=hidden] {
color: darken(@main-color, 30%);
font-size: .65em;
font-weight: normal;
top: -(round(@icon-size / 2.5));
opacity: 1;
visibility: visible !important;
}
.search__field:input-placeholder[style*=hidden] {
color: darken(@main-color, 30%);
font-size: .65em;
font-weight: normal;
top: -(round(@icon-size / 2.5));
opacity: 1;
visibility: visible !important;
}
View Compiled
This Pen doesn't use any external JavaScript resources.