Equal Height Columns Width Issue
I have 3 columns that extend to equal height. The only problem now is that if I have 2 columns only they expand their width and take 100% of the main container. So basically I need
Solution 1:
Okay, finally here is my working jsFiddle demo. See http://jsfiddle.net/rfjg4/10/show/ for the result.
I added the class col2
to the second wrapper and the CSS:
.wrapper.col2:after {
content: "";
display: table-cell;
width: 30.3%;
margin: 015px3px;
background-color: #fff;
text-align: center;
height: 100%;
padding-bottom: 2px;
}
With the above code a new cell with empty content is added to the <div class="wrapper col2">
tag.
Alternatively you can avoid the col2
by using CSS 3 selectors:
wrapper:first-child:nth-last-child(3) ~ div::after {
content: "";
display: table-cell;
width: 30.3%;
margin: 015px3px;
background-color: #fff;
text-align: center;
height: 100%;
padding-bottom: 2px;
}
See this jsFiddle or http://jsfiddle.net/rfjg4/11/show/ for an example. (See this Stackoverflow question Can CSS detect the number of children an element has? for explanation of the selectors).
Some notes:
- In your jsFiddle example you used two times
id="wrapper"
for a<div>
. You have to change theid
to aclass
(and update your CSS) - There is one
</div>
extra in line 17 (and in other lines, too). Those tags are marked red in jsFiddle. - You do not need
position:relative;
in your CSS (I deleted it in the example).
Post a Comment for "Equal Height Columns Width Issue"