I have a layout with two columns - a left div
and a right div
.
The right div
has a grey background-color
, and I need it to expand vertically depending on the height of the user's browser window. Right now, the background-color
ends at the last piece of content in that div
.
I've tried height:100%
, min-height:100%;
etc.
This is what worked for me:
Use
position:fixed
instead ofposition:absolute
, that way even if you scroll down the division will expand to the end of the screen.Here's a fix for the height.
In your CSS use:
For browser that don't support
vh-units
, use modernizr.Add this script (to add detection for
vh-units
)Finally use this function to add the height of the viewport to
#your-object
if the browser doesn't supportvh-units
:If you use
position: absolute;
and jQuery, you could useYou need to do two things, one is to set the height to 100% which you already did. Second is set the position to absolute. That should do the trick.
Source
One of the options is using CSS table. It has great browser support, even works in IE8.
JSFiddle Example
You can use the view-port unit in CSS :
HTML :
CSS :