Fluid Layout with 100% height
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
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.
position absolute for the side bar moves the rest of the page
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 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
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.
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
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)
+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.
@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).
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();
Maybe this will help someone: http://jsfiddle.net/8SrUb/4/
@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();
I just joined GitHub to +1 this thread. There is a lack of good documentation on this subject.