I need to create an input text box with a bottom border and the side borders should span half the height of the input on left and right.
Is there an easy way to design this in CSS?
Image is show below:
I need to create an input text box with a bottom border and the side borders should span half the height of the input on left and right.
Is there an easy way to design this in CSS?
Image is show below:
With 2 box-shadows, you can achieve the bottom border and small borders on both sides. Here is an example:
The spread radius and the X/Y offset of the box-shadows need to be tweaked according to the height of the input and the desired height of left/right borders. As you can see in this example with a different height on the input:
Browser support for box-shadows is IE9+.
You can use pseudo elements :
I would go for a slightly different approach to web-tiki's answer, and use a wrapper div and a pseudo element, as this would not require a fixed height input (but would require this extra element):
A
linear-gradient
based answer already exists in this thread but it is a bit complex and makes use of multiple linear gradients to achieve the border but it can be done with just onelinear-gradient
.Using
border-bottom
on the element avoids the need for one of those linear gradients. Using a linear gradient which is colored for 2px (2 x required border width), repeats in the X-axis and has a negative offset forbackground-position
in X-axis can produce border on left and right using only one gradient instead of two. The negative offset is equal to border's width (1px). It means that 1px of the gradient is visible on left side and since the gradient repeats in X-axis (and its size is only 100%), the 1px border on the right side is produced by the second tile of the gradient.A few advantages of this approach are:
input
elements are self-closing and so cannot have pseudo-elements, this implies that no extra wrapper elements are required.input
element's dimensions change.One drawback is that
linear-gradient
background images are supported only from IE10+.Maybe this could be an elegant solution.
If you use background then you can specify really nicely where what goes and it improves readability a bit.