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?
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?
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:
With css:
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:The following CSS adds a pseudo-element before any
div
element that's the adjacent sibling of anotherdiv
element:JS Fiddle demo.
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
.You could create an image of whatever height you wish, and then position that with the CSS background(-position) property like:
Instead of
center top
you can also use pixel or % like50% 100px
.http://www.w3.org/TR/CSS2/colors.html#propdef-background-position
Only using
line-height
not bad .. but try this one ... (should works for all but ist just -webkit included)
//Feel free to edit and add all other browser..
I was just looking for this... By using David's answer, I used a span and gave it some padding (height won't work + top margin issue)... Works like a charm;
See fiddle