I read about several different solutions to simulate equal-height columns or elements, but none of them really captured my attention because they were using hacks, incredibly complex HTML layouts or not widely supported attributes.
Here's the example Fiddle.
My goal would be to make sure all the elements have the same height or, at least, the maximum height of the siblings in the row.
A row is composed by 3 elements (in this case, no row wrapper exists but I may consider to add such container element).
Is there a solution that:
display: table
@vsync: If you want to make them the same height, make them the same height. For most layouts the "illusion" is sufficient and acceptable. Html/Css is a limited markup language so there is only so much it can do before you have to rely on another tool.
Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.
The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.
Basically what you do is make both divs/columns very tall by adding a padding-bottom: 100% and then "trick the browser" into thinking they aren't that tall using margin-bottom: -100% .
With the restrictions you made: No, there isn't.
edit: Because you didn't mention this: You could use tables for this. (welcome back to the 90s)
You can use CSS3 flex property for this. Write like this:
CSS
.parent{
display:-moz-box;
display:-webkit-box;
display:box;
-moz-box-orient: horizontal;
-webkit-box-orient: horizontal;
box-orient: horizontal;
width:100%;
min-height:200px;
}
.parent div{
background:red;
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
border:2px solid green;
}
HTML
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
Check this http://jsfiddle.net/VkPmg/2/
If you have a fix width layout, you can fake it by background-image. Imagine a tile image background that simulate the borders, you will just have to repeat-y in the main container.
For example if you have a 400px container with 3 100px box floating (like your fiddle), you will have to make a 1x400 image repeating in the main container. Just add in this image at the good x position 1 pixel look like the border color you used. And repeat it !
With this technique, your box will not have the same height (in reality) but the display will look like the boxe have it because the higher box will push the container and the background will appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With