I've got a text input element which is decorated with an underline. The underline goes up half the height of the input on either side of it and turns blue when the input is focused. It's similar to how inputs look on Android devices.
Here's a JSFiddle and some accompanying code.
<span class="input-underline-wrapper">
<input placeholder="Search..." type="text" value="">
<div class="underline"></div>
</span>
// Start:normalize
*, *:before, *:after {
box-sizing: border-box;
}
input:focus {
outline: none
}
// End:normalize
.input-underline-wrapper {
display: inline-block;
width: 100%;
}
input {
width: calc(100% - 2px);
margin-left: 1px;
padding-bottom: 2px;
}
input[type=text] {
border: 0;
cursor: text;
}
.underline {
background-color: #ebebeb;
transition: color 0.3s, background 0.3s, border 0.3s, text-shadow 0.3s;
z-index: 0;
height: 5px;
margin-top: -4px;
width: 100%;
}
input:focus ~ .underline {
background-color: #4EA6EA;
}
This all works well and good, but it feels a bit verbose. I'm wondering if I've missed something simple here. Is it possible to achieve the same effect using a white box-shadow which covers the upper-half of the input and omit using a wrapper and a second, underlining div? I only need to support the latest version of Google Chrome.