Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill 100% of remaining height?

+--------------------+ |                    | |                    | |                    | |                    | |         1          | |                    | |                    | |                    | |                    | +--------------------+ |                    | |                    | |                    | |                    | |         2          | |                    | |                    | |                    | |                    | +--------------------+ 

Contents of (1) as shown above are unknown, as it may increase or decrease in dynamically generated pages. The second div (2) as shown above, should fill the remaining space.

here is an example of my html

<div id="full"> <!--contents of 1 --> <div id="someid"> <!--contents of 2 --> </div> </div> 

css...

#full{width: 300px; background-color: red;} #someid{height: 100%;} 

Or is this method wrong? How should I do this? please see my demo and show me my mistake.

like image 384
Bhojendra Rauniyar Avatar asked Mar 13 '13 03:03

Bhojendra Rauniyar


People also ask

What does min-height 100% do?

You could consider min-height: 100vh; . This sets the height equal or greater to the size of the screen, vh: vertical height .


2 Answers

You should be able to do this if you add in a div (#header below) to wrap your contents of 1.

  1. If you float #header, the content from #someid will be forced to flow around it.

  2. Next, you set #header's width to 100%. This will make it expand to fill the width of the containing div, #full. This will effectively push all of #someid's content below #header since there is no room to flow around the sides anymore.

  3. Finally, set #someid's height to 100%, this will make it the same height as #full.

JSFiddle

HTML

<div id="full">     <div id="header">Contents of 1</div>     <div id="someid">Contents of 2</div> </div> 

CSS

html, body, #full, #someid {   height: 100%; }  #header {   float: left;   width: 100%; } 

Update

I think it's worth mentioning that flexbox is well supported across modern browsers today. The CSS could be altered have #full become a flex container, and #someid should set it's flex grow to a value greater than 0.

html, body, #full {   height: 100%; }  #full {   display: flex;   flex-direction: column; }  #someid {   flex-grow: 1; } 
like image 124
thgaskell Avatar answered Nov 14 '22 04:11

thgaskell


To get a div to 100% height on a page, you will need to set each object on the hierarchy above the div to 100% as well. for instance:

html { height:100%; } body { height:100%; } #full { height: 100%; } #someid { height: 100%; } 

Although I cannot fully understand your question, I'm assuming this is what you mean.

This is the example I am working from:

<html style="height:100%">     <body style="height:100%">         <div style="height:100%; width: 300px;">             <div style="height:100%; background:blue;">              </div>         </div>     </body> </html> 

Style is just a replacement for the CSS which I haven't externalised.

like image 24
Serdalis Avatar answered Nov 14 '22 04:11

Serdalis