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?
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.
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 .
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%.
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.
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.
Only using line-height
line-height: 10px;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With