Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control border height?

Tags:

html

css

layout

I have two div, one on the left and the other is on the right. Now I want to divide this two div with a border between them. But the border with full height looks bad.

I want to control the height of the border. How could I do this?

like image 803
Jichao Avatar asked Oct 17 '10 12:10

Jichao


People also ask

How do you adjust the height of a border?

You can set height to inherit for the height of the table or calc(inherit - 2px) for a 2px smaller border. Remember, inherit has no effect when the table height isn't set. Use height: 50% for half a border.

How do I lower left border height in CSS?

You can't. CSS borders will always span across the full height / width of the element. One workaround idea would be to use absolute positioning (which can accept percent values) to place the border-carrying element inside one of the two divs. For that, you would have to make the element position: relative .

How do you limit the length of a border?

To adjust the border length, you can use the width & height properties of these pseudo-elements. In the following example, we have added a blue bottom border to the div element and we have shortened it to 50% by setting the width of the ::before element to 50%.

How do you shorten a border line?

The Borders run from Left to Right Margin. If you want them to be shorter go to Format> Paragraph & apply Left & Right Indentation to the bordered paragraph.


2 Answers

A border will always be at the full length of the containing box (the height of the element plus its padding), it can't be controlled except for adjusting the height of the element to which it applies. If all you need is a vertical divider, you could use:

<div id="left">   content </div> <span class="divider"></span> <div id="right">   content </div> 

With css:

span {  display: inline-block;  width: 0;  height: 1em;  border-left: 1px solid #ccc;  border-right: 1px solid #ccc; } 

Demo at JS Fiddle, adjust the height of the span.container to adjust the border 'height'.

Or, to use pseudo-elements (::before or ::after), given the following HTML:

<div id="left">content</div> <div id="right">content</div> 

The following CSS adds a pseudo-element before any div element that's the adjacent sibling of another div element:

div {     display: inline-block;     position: relative; }  div + div {     padding-left: 0.3em; }  div + div::before {     content: '';     border-left: 2px solid #000;     position: absolute;     height: 50%;     left: 0;     top: 25%; } 

JS Fiddle demo.

like image 176
David Thomas Avatar answered Sep 28 '22 08:09

David Thomas


Only using line-height

line-height: 10px; 

enter image description here

like image 30
Đinh Tiến Vũ Avatar answered Sep 28 '22 06:09

Đinh Tiến Vũ