Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input with border for half height

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: Input with border on half of it's height

like image 715
anu g prem Avatar asked May 07 '15 09:05

anu g prem


People also ask

How do you adjust the height of a border?

Adding <td class="border"> with a div nested in it, will allow you to make a border that you can style as you please. Set a width and height on the div, then a bg color. Then position it vertically with a top margin. That will resemble your image and allow you to fine tune it.

How do you add a border to the input field?

You can use the CSS border property to add a border around your HTML textboxes. You can also use border-width , border-style , and border-color , but the border property covers all of these anyway.

How do I reduce the height of a border in HTML?

Adjusting the Margin Size of an HTML Element With CSS You can remove this margin by setting the top and left margin to zero. Like the padding and border, the sizes of specific sides of the margin can be set using margin-left , margin-right , margin-top , and margin-bottom .


2 Answers

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.

input[type="text"] {
  padding: 10px;

  background: linear-gradient(#000, #000), linear-gradient(#000, #000), linear-gradient(#000, #000);
  background-size: 1px 20%, 100% 1px, 1px 20%;
  background-position: bottom left, bottom center, bottom right;
  background-repeat: no-repeat;

  border: none;
  color: #999;
}
<input type="text" />
like image 76
Criss Lion Avatar answered Oct 13 '22 01:10

Criss Lion


With 2 box-shadows, you can achieve the bottom border and small borders on both sides. Here is an example:

input[type=text] {
  width:300px; height:17px;
  border: 0; outline:none;
  padding:0;
  box-shadow: -5px 5px 0px -4px #000, 5px 5px 0px -4px #000;
  text-align:center;
}
<input placeholder="Email" type="text" value=""/>

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:

input {
  width:300px; height:40px;
  padding:0;
  border: 0; outline:none;
  box-shadow: -18px 18px 0px -17px #000, 18px 18px 0px -17px #000;
  text-align:center;
}
<input placeholder="Email" type="text" />

Browser support for box-shadows is IE9+.

like image 36
web-tiki Avatar answered Oct 13 '22 00:10

web-tiki