How to make sure that two divs have the same height?
Unfortunately, there is no ideal method for this without using Javascript, since realistically two divs do not know anything about each other.
What your options depend on what exactly you were looking for visually.
A quick google search brought this, which looks pretty promising: http://www.vanseodesign.com/css/equal-height-columns/
If you can focus on more modern browsers, you can avoid using flexbox. See this post for examples, etc.: http://css-tricks.com/fluid-width-equal-height-columns/
There's a pretty cool trick on how to do this.
First you apply padding-bottom: 100%; to each side by side div.
Then you apply margin-bottom: -100%; to each side by side div. Pay attention to -
Finally, you add overflow:hidden; in the div in which they are located.
Presto! True happiness is yours.
HTML:
<div id="wrapper"> <div id="primary">Lorem ipsum dolor set amet. </div> <div id="secondary">En arche yn ho logos. Kai ho logos yn pros ton theon. Kai theon yn ho logos. En arche yn ho logos. Kai ho logos yn pros ton theon. Kai theon yn ho logos. </div> </div> CSS
#wrapper {overflow:hidden;} #primary {width:50%; float:left; padding-bottom:100%; margin-bottom:-100%;} #secondary{width:50%; float:left; padding-bottom:100%; margin-bottom:-100%;} Literature:
If you specify a height value for your container, say #wrapper {height:300px;} , you can just set the height value #primary and #secondary to 100% . But if you do not want to specify a height value, you can use the display:table option, as in the example here http://jsfiddle.net/qiqiabaziz/LFEF5/
Your CSS .table{display:table;width:99.98%;margin:0 auto;padding:0 0.01% 0 0.01%;border-collapse:separate;border-spacing:5px;} .row{display:table-row;} .cell{display:table-cell;text-align:center;width:50%;} Your HTML <body> <div class="table"> <div class="row"> <div class="cell">content for this div </div> <div class="cell">content for this div </div> </div> </div> </body> just make sure the parent div (div wrapper) has a width in pixels
<div id="wrapper"> <div id="primary"></div> <div id="secondary"></div> </div> #wrapper { width:300px; } #primary { width:50%; float: left; } #secondary { width: 50%; } this will work if the primary div has no field and / or padding
All Articles