I think this is not possible without jQuery. The main problem is taking into account the variable height of the elements.
link here: http://jsfiddle.net/uqZgt/1/
HTML:
<div class="container"> <div class="box-1"> This box has alot of content. This box has alot of content. This box has alot of content. </div> <div class="box-2"> This box has a little bit of content. This box has a little bit of content. This box has a little bit of content. This box has alot of content. This box has alot of content. This box has alot of content. </div> </div>
CSS:
.container { width: 242px; } .container div { width: 100px; background: #ff0000; float: left; padding: 10px; border-right: 2px solid #000 } .box-1 + .box-2 { border-right: none; border-left: 2px solid #000 } .box-1 ~ .box-2 { margin-left: -2px }
in this example, all .container in the .container div have a 2px solid black border to the right. However, an element with class box-2 , which directly passes an element with .box-1 , will have a solid black border with a resolution of 2px and without border-right. For now, this creates a 3px border between the two elements.
Now .box-1 ~ .box-2 selects any .box-1 that immediately precedes .box-2 and sets its margin-left to -2px. This drags it from two pixels to the left, which actually overlaps the borders of both elements.
.container div has a width equal to the sum of the width of the two elements (200px), plus padding (10px left and right = 20px) plus the width of one of the borders (2px). 242px, so the two elements are perfect.
No matter which div has the most content, the border will be displayed as the height of the div with the most content.
source share