bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Fluid Layout with 100% height

Open BenjiZombie opened this issue 14 years ago • 13 comments

Hi,

Been trying to create a fluid layout with content that will stretch to 100% of the client area of the browser window. Say I have the following:

<div class="container-fluid">
    <!-- Header -->
    <div class="masthead">
        <!-- Tabbed navbar -->
    </div>

    <!-- Content -->        
    <div class="tab-content">
        <div class="tab-pane fade in active" id="1">
            <div class="row-fluid">
                <div class="span3">
                    <!-- Sidebar -->
                    <div id="accordion2" class="accordion">
                        ....
                    </div>
                </div>
                <div class="span9">
                    <!-- Google Maps Control -->
                    <div id="map"></div>
                </div>
            </div>
        </div>
    </div>
</div>

So what I'm looking for here is for the accordion sidebar to be at 100% height as well as the Google Maps control. Any clues on how to do so?

So far I have the html and body height set at 100% and the container-fluid set at min-height 100%:

html, body { height: 100%; } .container-fluid { min-height: 100%; }

But I cannot get anything else to stretch.

Thanks

BenjiZombie avatar Feb 03 '12 15:02 BenjiZombie

Bootstrap doesn't provide this out of the box, but may in the future with an additional example layout. For now, one solution is to use position absolute for the sidebar—top: 0, left: 0, bottom: 0—as simply setting heights won't do anything for you.

mdo avatar Feb 05 '12 09:02 mdo

position absolute for the side bar moves the rest of the page

pixelmixture avatar Feb 14 '12 00:02 pixelmixture

I would suggest adding "height: 100%" and "position: absolute" only to the body and "height: inherit" from body to the containing elements. You dont have hacky positionings as you would have with "position: absolute;" on every container and you dont have to touch your own classes for this. This will also not move the rest of your page. The elements simply have big parents where they can fit into with "height: 100%".

Example:

body {
    height: 100%;
    width: 100%;
    position: absolute;
}

.container-fluid,
.row-fluid { height: inherit; }

danwit avatar Feb 14 '12 21:02 danwit

@danwit Your example works only for the 1st row-fluid in the page. How could it adapted so that the 1st row-fluid has a regular height, and the 2nd has 100% from the rest of the viewport?

e.g.

    <body>
<div class="container-fluid" id="app"  style='height: inherit;'>

    <!-- header -->
    <div class="row-fluid">
                <div class="span6">header1</div><div class="span6">header2</div>
    </div>
    <!-- main content, should be 100% -->
    <div class="row-fluid " style='height: inherit;'>
                ...
    </div>
</div>
</body>

Thanks

mariusa avatar Feb 25 '12 19:02 mariusa

if you assign a height of 100% to the second container, it gets the full height of the current inner window. You have to define a height for the first container too, like: 10-90% or 20-80%. If you want to dynamically switch the heights you have to use javascript afaik.

danwit avatar Feb 25 '12 21:02 danwit

Could You give a working example of this? This topic is difficult and unfortunately it's often main requirement from customer...

Thank You in advice

matma avatar Mar 02 '12 12:03 matma

this is a really important thing. I would say it would be great to have something like http://layout.jquery-dev.net/demos/example.html, but without south and east panes (maybe for someone who ends up here, that link is useful)

jperelli avatar Apr 07 '12 02:04 jperelli

+1 for a bootstrap layout plugin. I'm using bootstrap for the ui prototype of a web app and thus like to position my ui elements in "auto-resizing" panes to avoid browser window scrollbars.

fbuchinger avatar Apr 23 '12 07:04 fbuchinger

@matma - here's a jsfiddle http://jsfiddle.net/amorris/dmyTR/ using the fluid layout with a collapsable panel for google maps, and an accordion panel that stays at 100% height. (Or, slightly less, as I use a title bar).

adammorris avatar Nov 26 '12 10:11 adammorris

I used this piece of code that seems to work well across FF/Chrome/IE9/Safari. It defining the height of the of my right div "sidebar" by all of the content in my other column which is dynamic and exists under "span8". One problem is that you need to set a min-height in your div style if you want it to display when there is no content in your other div.

$(window).resize(function(){ var height = $(".span8").height() $('.sidenav').height(height); //alert(height); }) $(window).resize();

mitchpark avatar Jan 09 '13 15:01 mitchpark

Maybe this will help someone: http://jsfiddle.net/8SrUb/4/

minusreality avatar Apr 14 '13 14:04 minusreality

@minusreality So close! But if you have other elements (eg nav bar) then the height is too tall by the height of the navbar. The problem is exacerbated by responsive layouts in which the navbar can dynamically stack vertically. http://jsfiddle.net/8SrUb/16/

I am using this bit of js to do the trick:

    // Fluid layout doesn't seem to support 100% height; manually set it
    $(window).resize(function(){
        $('#map').height( $(window).height() - $(".navbar").height() 
                        - parseInt($(".navbar").css("margin-bottom"))
                        - parseInt($(".navbar").css("margin-top")) 
                        - parseInt($('#map').css("margin-bottom"))
                        );  
    })
    $(window).resize();

xEtherealx avatar May 07 '13 19:05 xEtherealx

I just joined GitHub to +1 this thread. There is a lack of good documentation on this subject.

ghost avatar Jul 25 '14 00:07 ghost