This question already has an answer here:
- Input with border for half height 5 answers
I have an input field with only a border at the bottom, now I need to create a little line on the left and right of the input. It is a little hard to describe, so I will use an example:
input {
background-color: transparent;
height: 20px;
padding: 10px 10px 1px;
border: 0;
border-bottom: 1px solid red;
}
<input type="text" placeholder="Example">
You can do this with
:after
and:before
pseudo elemnts.A way to produce a responsive bowl shaped underline which need not be modified irrespective of the padding that is applied on the element is to use
linear-gradient
as background image. They can be givenbackground-size
in pixel values and be positioned at the bottom of the element.The approach itself is fairly simple:
border-bottom
of 1px thickness to produce the bottom border.background-size
setting determines the height of the left and right borders. In the snippet, I have set the background size as100% 5px
and so 5px will be the fixed height of the left and right borders. Their height can be increased on decreased by modifying just this parameter alone.background-repeat
is set so that the background image repeats in the x-axis and by setting a negative offset of 1px for thebackground-position
, we make sure only 1px of the 1st gradient tile's red border is shown on the left. Since we have repeat-x on and the background-size is only 100%, the second tile in the x-axis will start from 1px before the end on the right itself and so this would produce the 1px border on the right side.Note: Box shadow has the edge over this approach in terms of browser support. This is only IE10+.
Using multiple box-shadows on the input can let you have this underlining effect:
The spread radius and the X/Y offset of the sbox-shadow need to be tweaked according to the height of your input as you can see in this example with a higher input :
Browser support for box-shadows is IE9+.