height of 100% not working on side navigation - css

For the life of me I cannot get my side navigation to expand to the bottom of my page. I've googled this and looked at many other stack overflow questions related to this but nothing is helping.
People have suggested setting a height on the parent div, since height: 100%; doesn't know what the 100% is. But how does the parents height know what 100% is?
I also cannot use any "fixed" or "absolute" positioning because that seems to completely break the responsiveness of Twitter Bootstrap.
Here is my code:
<div id="secondary">
<div class="span10" style="background-color: #860038; min-height: 100%; overflow: hidden;">
<ul class="side-nav">
<?php if (!empty($secondary_menu)): ?>
<?php foreach ($secondary_menu as $key => $menu): ?>
<?php $active = ($this->uri->segment(2,'index') == $key)? 'side-box-active': 'side-box'; ?>
<li class="<?= $active ?>"><?= $menu['label']?></li>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
</div>
So the above code creates my side navigation dynamically throughout my application. I'm using Twitter Bootstrap and on the div class="span10" I put my background-color for the side nav and min-height: 100%. (Also overflow:hidden).
What this is currently doing is creating my container but it cuts off right when the navigation stops, rather then expanding to the bottom of the page.
As you can see, I setup a parent div with ID="secondary", in case we need it.
Screenshot shows the side navigation. I need the maroon red color to expand to the bottom of my screen. Scratch that it lets you post pictures then explain them and then tells you you can't post pictures :) sorry no image I guess.
Thanks for any help in advance.

In order for 100% height to work, parent elements need 100% height as well, including html and body.

Not sure if you've solved the problem, but if someone doesn't:
When you have a background image or color that you want to repeat all the way down the page, but within that page you have columns of different lengths, the only way to accomplish this is to put the background image or color in the container which will then hold the different lengths of column.
Said columns will expand down according to the amount of content you put within them. The longest div inside the container will make the background image repeat-y (down) or the color.
So your structure would look like this:
<div id="container"> <!--which is the #1 element in your body-->
<div id="leftcolumn"> Your side-nav would go here</div>
<div id="rightcolumn">Your main content which is usually longer
than the menu will go here</div>
</div><!-- end container-->
Obviously in this situation your header and footer div would be placed outside the container div and may need to go within another wrapper div to keep everything centered.
And with, for example, the following CSS, it'll work just fine:
<style>
html,
body {
height:100%;
background-color : #103C52; /* or whatever you like*/
}
#container {
height:100%;
background-color: green; /* or whatever you like*/
}
#leftcolumn {
height:100%;
width: 16.67%; /* or whatever you like*/
background-color: red; /* or whatever you like*/
float: left;
}
#rightcolumn {
height:100%;
width: 80%; /* or whatever you like*/
overflow-x: hidden; /* or whatever you like*/
overflow-y: scroll; /* or whatever you like*/
background-color: blue; /* or whatever you like*/
float: left;
}
</style>
If this is not clear, post what you have so far and I will take a look at it... ;)

Related

Why my width: 100% wrapper doesn't work properly?

I put all my content in wrapper that 100% width. my wrapper is not a child.
<body>
<div id="wrapper">
<?php require_once("header.php"); ?>
<?php require_once("content.php"); ?>
<?php require_once("footer.php"); ?>
</div>
CSS:
#wrapper {
overflow-x: hidden;
height: 100%;
width: 100%;
background-color:#fff5e5;
}
But browser (chrome, moz) shows that:
Thanks for help.
An element in your page is rendering outside of <body> element. This can be the result of many causes (negative margins, large widths, large paddings) and guessing it is waste of time. Create a minimal, complete and verifiable example and I'll find it in minutes.
If you don't care what is the cause and only want to remove the effect, (which is clearly the wrong way to go about it and I strongly advise against), you can always apply
body {
oveflow-x: hidden;
}
If it is main wrapper,Only adding
display:block;
must solve your issue.
You might want to check if your content inside of the wrapper takes up 100% of the space. If you hover over the element in the debug, a blue box will show up. If it is 100% of the width, then that means that the content inside probably only spans part of the screen width.

What's causing the body tag to widen?

I'm using Skeleton CSS Boilerplate
Two different pages of my website, similarly structured, are slightly laterally shifted away from each other. This is causing a jarring effect in the navigation bar when navigating from one page to the other.
Upon investigation, I noticed in the Chrome Dev Tools CSS inspector that the body tag of each page is a different width.
The structure of both pages is the same, shown below. The class .wrap has a max width of 960px, and all the content is contained within .container .wrap.
<body>
<?php
require 'navsub.php';
?>
<div class="container wrap" id="singlepageajax">
</div>
<?php
include 'footer.php';
?>
</body>
So... what could be causing the body tags to be different widths?
Add the following CSS code
html, body {
height: 100%;
overflow: hidden;
}
then add a <div id="container-wrapper"> to wrap up the container
place its CSS like
#container-wrapper {
height: 100%;
overflow-x: auto;
position: absolute;
width: 100%;
}
this will enables the scrolling again
Vertical scroll bar is the cause.
The body element will shrink in horizontal direction to add some free space for the scroll bar, as the browser window has fixed amount of horizontal space.
UPDATE
If you want to prevent this behaviour, you may use:
body{
overflow: hidden;
}
But you may lose the scrolling feature of your browser on the page.

How to making full height on every screen for section or div inside body?

Hi all am created a html layout having two sides left and right left one having navigation menu and right having contents
i need both has full-height has to come to bottom of the screen even there is very low contents.
now it looks like
here my fiddle
demo
moreover i tried full height for body and html to
body, html{
height:100%;
}
(relevant) HTML:
<div class="wrapper">
<div class="left">
<!-- stuff -->
</div>
<div class="spacer"></div>
<div class="right">
<!-- stuff -->
</div>
</div>
(relevant) CSS:
body, html {
height : 100%;
}
.wrapper {
width : 600px;
display : table;
margin : 0 auto;
height : 100%;
}
.left, .right {
display : table-cell;
}
.left {
width : 30%;
}
.right {
width : 65%;
}
.spacer {
display : table-cell;
background : transparent;
width : 5%;
}
Running Demo
I used normalized.css to reset the styles and avoid the default margins otherwise applied to the display: table; div. Try removing it on the demo (External Resources menu on the left) to see what I mean.
Take a look here to read something else on CSS Resets.
EDIT: added the transparent spacer.
Use :
display: table-cell
Here's the result:
http://jsfiddle.net/GhxQL/6/
You've got the right CSS in your fiddle; you just have some errors in the code.
Make sure your lines of CSS end in ; instead of : – there are a few lines in which you have colons instead of semicolons. And change your first line from htm, body to html, body.
Updated fiddle: http://jsfiddle.net/hqkVh/7/
Ok Let's make the equation HARDER !!
so if you have RESPONSIVE WEB DESIGN and WANT TO USE BOTH HEIGHT and MIN-HEIGHT and also Height All the Time 100% What's THEN ?
if you use HEIGHT 100%, u cant handle All of the content of your columns, It's obvious by resizing the browser the Height is 100% and the content dont show completely
You might wanna CHECK THIS SOLUTION from my own question, the MIN-HEIGHT Solution
PLEASE CONSIDER THESE QUESTIONS ARE NOT DIFFERENT JUST THE WAY OF ASKING IS DIFFERENT
I suggest Use Min-Height 100% and Height Auto

Javascript's call ruin floating in Firefox

I have the page with the structure:
<div id="container">
<div id="header">top menu</div>
<div id="content">content</div>
<div id ="footer" align="center">
<div class="left">left part of footer menu</div>
<div class="right">right part of footer menu</div>
</div>
</div>
Css style:
#container {
position:relative;
height:auto !important;
height:100%;
min-height:100%;
}
#content {
padding:0em 0em 12em;
}
#footer {
position:absolute;
width:100%;
bottom:0;
}
.left {
float: left;
}
.right {
float: right;
}
That works fine in all browsers. But when I add
<script type="text/javascript"></script>
inside
<div class="left">
in FireFox(only) the part of footer after the script come up to the top - between header and content divs.
What's wrong with it?
UPD
This all was about wrong mark-up inside #content. And only FireFox didn't understand when I missed one of closed table tag:) Thank you guys, you helped me to sort it out.
The #footer has absolute position and is inside the relatively positioned #container div so I would expect this. Maybe try making container absolutley positioned.
Also I think your markup is not what you intended. There are one too many opening div tags.
change the #container height from auto to 100% and remove the extra lines for height.
The auto is messing up the calculations as it overrides the 100% lines due to the !important value
Since #footer's position is absolute, with bottom 0, it will be positioned relative to its first (non statically positioned) parent, which is #container. Essentially what's happening here is that #container is becoming mush less high, and dragging #footer with it.
That's happening because you have two height: settings in the css for #container (somehow the script tag triggers it to refresh) so the behaviour would be undefined.
If you're trying to make the footer stick to the bottom of the window, including as it's resized, I'd advise having a javascript function handle it, triggered by the window's resize event (it's fairly simple, see this question on javascript window resize event
You could try the CSS a different way with absolute positioning. I try and avoid float as it can lead to unexpected rendering issues. See this jsFiddle for an alternate approach. Working in IE6, Chrome12 and FF3.6 and FF4 for me.

Centering float left div's in the body

i have this piece of code
<body>
<? while.. (blah blah blah){ ?>
<div class="product">
something
</div>
<? } ?>
</body>
and the css file is
.product{ width:350px; float:left; }
the problem is that body doesn´t have a width, well... actually it has, 90%, but my problem is on the different resolutions, it works perfect for me (1680px width) but when i switch to 1024 as example, the products seems to be off (aligned to the left)
is there any posibility to center those divs with a non static with on their parent container?
If you want multiple divs, all centered as a group, you'll have to wrap them in a parent div, then center that using margins.
Your other option would be to make them display: inline; and use text-align: center on the body to center them. (Or consider making them spans, which default to inline)
if you turn floating off, you can use
margin-right: auto;
margin-left: auto;
If you declare a width in percentage for the div, and then do margin-left:auto;, margin-right:auto;, would that be OK?
You could give the images some left and right padding and that should make your images centered.

Resources