Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to size a div's height to its container height, using CSS?

Tags:

html

css

How to size a div's height to its container height, using CSS ?

<div class='container'><br>
  &nbsp;&nbsp;<div style='display: block; height: 500px'>left</div><br>
  &nbsp;&nbsp;<div id='to-be-sized' >right</div><br>
</div>
like image 897
Prakash Raman Avatar asked Dec 10 '09 13:12

Prakash Raman


2 Answers

You can either:

  • use the incomplete but philosophically correct path of pure CSS and face every kind of incompatibility between browsers

or

  • write 3 lines of dirty semantically incorrect and devil made table and have it work perfectly everywhere

Your pick :)

like image 86
Matteo Riva Avatar answered Oct 18 '22 21:10

Matteo Riva


There's a way to do this IF you happen to be using jQuery. As you asked for CSS this might not be an option available to you, but if you can utilise it it will do exactly what you want.

$(divToResize).css('height',$(container).innerHeight());

$(divToResize) is the selector for the DIV you wish to match the height of it's container and $(container) is logically the container whose height you want to get.

This will work regardless of if the container's height is specified in CSS or not.

like image 43
KyokoHunter Avatar answered Oct 18 '22 19:10

KyokoHunter