Pure CSS search input + search icon button. NO img, NO js.
Created
July 3, 2017 21:57
-
-
Save t0mab/1679912bb5e6159639f50b4ca2f93912 to your computer and use it in GitHub Desktop.
Pure CSS search input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="search-bar"> | |
<input type="text" placeholder="input some text here..." required></input> | |
<div class="search-icon"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* because fuck JS, that's why. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, body { | |
background-color: #7EC833; | |
height: 100%; | |
width: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
$size: 20px; | |
.search-bar { | |
height: auto; | |
width: auto; | |
position: absolute; | |
display: inline-block; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
box-sizing: border-box; | |
input { | |
height: 44px; | |
width: 44px; | |
padding: 10px 20px; | |
box-sizing: border-box; | |
font-size: 18px; | |
border: $size/10 solid transparent; | |
border-radius: 44px; | |
cursor: pointer; | |
background-color: transparent; | |
transition: all 0.5s ease-out; | |
color: transparent; | |
&::placeholder { | |
color: transparent; | |
} | |
&:invalid { | |
box-shadow: none; | |
} | |
&:hover { | |
border: $size/10 solid #FFF; | |
box-shadow: 0 0 $size/10 $size/10 #EEE; | |
} | |
&:focus, &:valid { | |
width: 300px; | |
border: $size/10 solid #CCC; | |
outline: none; | |
cursor: auto; | |
background-color: #FFF; | |
color: #000; | |
&::placeholder { | |
color: #999; | |
} | |
+ .search-icon { | |
z-index: 0; | |
border-color: #CCC; | |
right: 20px; | |
&:after { | |
background-color: #CCC; | |
} | |
} | |
} | |
} | |
} | |
.search-icon { | |
display: inline-block; | |
height: $size; | |
width: $size; | |
border-radius: 50%; | |
border: $size/10 solid #FFF; | |
position: absolute; | |
right: 12px; | |
top: 8px; | |
z-index: -1; | |
&:after { | |
content: ''; | |
position: absolute; | |
top: $size/2 + $size/4*1.414 + $size/10; | |
left: $size/2 + $size/4*1.414; | |
transform: rotate(45deg); | |
height: $size/10; | |
width: $size/2; | |
background-color: #FFF; | |
border-radius: 10px; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment