I tried this with DIVs. The problem occurs in both. I can't get the right border to be equal heights as the longest DIV. And I need this to work across the current desktop browsers from the days of IE7 and up.
This is a common problem, but it's 2011 now when I write this. Is there finally a way to do this with pure cross-platform CSS without resorting to funky tricks like pretending to make it work (such as a column cutoff)? Or, must I resort to jQuery to make it work in the least amount of fuss?
EDIT: My bad. When I wrote this originally, I included TABLE TDs having the problem as well as DIVs. But I didn't realiz开发者_运维知识库e that I had taken my test code and switched from DIV to TD, but my CSS still said float:left;clear:right. When I eliminated that with the TDs, the border extended to full height of the longest column. However, still, it would be good to find out how to do this with DIVs, but cross-platform from desktop browsers starting with the year IE7 came out and upwards.
A quick way to get the effect is having a background image with a segment of your border on your container div that repeats down the page. This will make the border extend as far as the parent container which should be the tallest column.
Hope this helps.
This approach is relatively "trickless" -- and it's the only approach I've found that works correctly, and doesn't involve any big-time hacks. (also, no tables - only divs and css).
You can see the following example in action: here (jsFiddle)
HTML:
<div class="colwrap">
<div class="col1 content">
<div class="col1 bg"></div>
unde omnis iste natus error
sit voluptatem accusantium
doloremque laudantium
</div>
<div class="col2 content">
<div class="col2 bg"></div>
abcdefg hijklmnop
</div>
</div>
CSS:
.colwrap {
position: relative;
overflow: hidden;
}
.colwrap .content {
float:left;
overflow: hidden;
}
.colwrap .bg {
position: absolute;
height: 100%;
z-index: -1;
}
.colwrap .col1 { width: 50px; }
.colwrap .col1.bg { background: blue; }
.colwrap .col2 { width: 50px; }
.colwrap .col2.bg { background: red; }
Notes
The only trick here, is that you have to split your background (or border) -- whatever visual element you want to fill the column with--into a separate div from the content.
Your columns must be fixed-width. percentage widths usually won't work out very well.
The content divs float within the wrapper, which is set to
overflow:hidden
. This way the content divs "push out" the wrapper to the full height of the largest content.Then the background divs are
position:absolute; height:100%;
. They automatically inherit the position (top,left) of their floating parents, but the height is computed based on the next positioned parent (not the floating content div, but the wrapper, withposition:relative;
). So the background divs end up right where we want.The bg divs also use
z-index:-1;
to force them behind the content. This works in webkit, and FF, but may not work correctly in IE (esp. older versions). If it doesn't work, the problem is likely the negative number. To fix it all you have to do, is add an additional wrapper around the text within the content div, then set z-index on bg and on your content wrapper, so that things stack the way you want. (of course, you should test it -- because it may not be a problem at all).Finally, I'll note that this same approach will work for as many columns as you want -- just add more (
.col3
,.col4
, and so on.), just likecol1
andcol2
shown above.
Could you provide a URL for your page? BG images would work if your markup was a certain way. I'd love to take a look at your page to see what you're trying to do.
精彩评论