css - How to set an element's height to be the same as its parent -


i have div called "content-left" within "main-content". want have child div assumes 100% of parent's height.

#main_content { display: table; width: 99%; margin-left: auto; margin-right: auto; }  #content-left { width: 250px; float: left; display: table-cell; padding-bottom: 8px; background-color: #f6f5f4; height: 100%; } #content-rightside { width: 782px; float: left; display: block; padding-left: 10px; } 

for height: 100%; css rules work, every parent of element must have explicit height defined. type of stylesheet work:

html, body, #main-content, #left-column, #right-column {     height: 100%; }  #left-column {     background-color: #ccc;     float: left;     width: 75%; }  #right-column {     background-color: #eee;     float: left;     width: 25%; } 

and here's fiddle at: http://jsfiddle.net/txrer/

update

if want height based on content, use display: table so:

#main-content {     display: table;     width: 100%; }  #left-column {     background-color: #ccc;     display: table-cell;     width: 75%; }  #right-column {     background-color: #eee;     display: table-cell;     width: 25%; } 

and here's updated fiddle: http://jsfiddle.net/txrer/1/

do note 1 draw of approach browser compatibility more of issue using css tables.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -