Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css border-left 50% height

Tags:

css

border

I want the left border of my div to show only to the half of the div. The same I would like to do to my right border but is should be set from the bottom of the div to the middle of the div. How can I achieve it?

like image 716
niao Avatar asked May 14 '10 20:05

niao


People also ask

How do I change border height in CSS?

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.


2 Answers

A sort-of similar but different approach to @Pekka's: use the :after pseudo-selector, like so:

.mybox {    position: relative;    padding: 10px 20px;    background-color: #EEEEEE;  }    .mybox:after {    content: '';    position: absolute;    bottom: 0px;    left: 25%;    width: 50%;    border-bottom: 1px solid #0000CC;  }
<div class="mybox">    Le content de box.  </div>

...and a jsFiddle for good measure.

like image 56
indextwo Avatar answered Sep 29 '22 11:09

indextwo


Good question. It's not possible using the border property.

The only thing that comes to mind, if you can set your div's position to relative, is to use an absolutely positioned, 1 pixel wide div. Not thoroughly tested but this should work:

<div style='width: 1px; top: 0px; bottom: 50%; left: 0px;              background-color: blue; overflow: hidden'>  &nbsp; </div> 

You'd do the same on the right hand side, replacing the left property by right.

Remember, the surrounding div needs to be position: relative for this to work. I'm not sure about whether the 50% height setting will work consistently throughout browsers - make sure you test it. You may have to resort to pixel measures if it doesn't.

like image 21
Pekka Avatar answered Sep 29 '22 12:09

Pekka