Trying to make the header height auto - css

My website here is a wordpress website but I believe the only thing I need to fix for an issue I'm having is the header height. The home page as a rotating banner which is 403px high and then all other pages have a header image of 303px high. I'm just trying to get the header height to be auto so the #container will automatically hug the bottom of the banner no matter it's height.
CSS
header { width: 960px; height: auto; margin: 0 auto; display: block;}
#container { width: 960px; margin: 20px auto; padding: 0 1.5em;}
What else should there be so the #container realizes that the header is there?
UPDATE:
NEW HTML
<div style="clear:both;"></div>
</div><!-- end of container-->
NEW CSS
#banner {
width: 960px; /* same with already defined */
height: 403px;
margin: 0 auto;
}
The only thinkg i did slightly differently was place the navigation under the header instead of the banner as it was underneath the banner of which i don't want. It looks the same however the doesn't seem to be doing anything differently then what I had previously. I still have that gap on the blog page under the banner.
I appreciate the help Zuul. I do think I have a bit more to go and then we can figure this out. Thanks!

The issue with the layout doesn't lay over the header tag, there are some elements positioned weirdly that are causing several problems:
This is a list of things to do in order to rectify the layout flow:
1)
Remove the <div id="banner"> from within the <nav id="main-navigation">.
The <nav id="main-navigation"> is set to height:70px and the slider is far taller than that.
Place it as a child of the <header> or after the <header> and before the <div id="container">.
e.g,
<header>...</header>
<div id="banner">...</div> <!-- here is better -->
<div id="container">...</div>
2)
After the first step, you can then remove from your #banner the following CSS:
REMOVE
#banner {
left: 50%;
margin-left: -480px;
position: absolute;
top: 69px;
width: 960px;
z-index: 1;
}
ADD
#banner {
width: 960px; /* same with already defined */
height: 403px;
margin: 0 auto;
}
3)
The step 01 and 02 should fix the #banner position along with the header height issue.
Now remains fixing the #container that contains floated elements and should be cleared at the end.
Here, your current class clearfix will not work, contains to many declarations, I would suggest:
<div id="container">
<div id="main">...</div>
<aside>...</aside>
<div style="clear:both;"></div>
</div>
Adding that new <div style="clear:both;"></div> at the very end of the #container will allow the float to be cleared and the document flow to resume normally.
EDITED
First phase is done, now the only thing you need to do is to remove the height from the #banner, and the gap will go away.
#banner {
width: 960px; /* keep this */
margin: 0 auto; /* keep this */
}

add a div with a style of clear:both just before your container div ends. This will allow to make the container div's height according to the contents inside it. You can make a class named clear and inside it you can put this style so that you can use this class anywhere in your website.

Related

Issue in sticky footer content in html5

I have created simple webpage using html5 and css.
I have created sticky footer with 4 columns and each column have vertical navigation menu.
Here is my code:
<footer>
<div id="footer">
<div class="footer-column" id="footer_column1">
Home
</div>
<div class="footer-column" id="footer_column2">
about us
</div>
<div class="footer-column" id="footer_column3">
contact us
</div>
<div class="footer-column" id="footer_column4">
Blogs
</div>
</div>
</footer>
and this is for css:
#footer {
position:absolute;
clear:both;
bottom:0;
color:#000;
width:100%;
height: 50px;
background:#fff;
left:0;
}
.footer-column {
float: left; /* Push the div as far up-left as it can be put */
width: 25%; /* Make sure to subtract the padding */
padding: 10px; /* We want padding on all sides to make things look nice */
text-align:center;
}
Now page looks like : s22.postimg.org/l0l6y85o1/Untitled_1_copy.png
If i increase the height of footer, it will be hidden background of slideshow.
Can anyone help me, how to fix this. Thanks in advance.
You have given absolute positioning to footer so it will stay there, now your page is basically overlapping it. You should use relative layout for your page.
I would suggest you to use bootstrap for this. Here is a simple example or this.
Regarding z-index - If you will give higher z-index to your footer say 999999 then it will be on top (higher than other elements on page).
Z-index will not actually help you with positioning. Always something will be hidden. If you want your footer to be right at bottom of the page then do not use absolute positioning and it will be pushed down.
Try:
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 100px;
}
#footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 100px;
}

How can I put white space at the bottom of my website, so the floating div never overlaps

I found a lot of questions on stack overflow about getting rid of white space, but I can't seem to figure out how to put it in.
I have a bottom navigation on my site that floats with the page, but if the window is small, the bottom part of the page gets covered up. I would like to insert some white space at the bottom, so when the window is smaller than the length of the page you can still read it.
I've tried adding:
margin-bottom: 50px;
padding-bottom: 50px;
to the div containing the top page content, but it doesn't work.
Is there something I am missing? Here's a demonstration: http://www.writingprompts.net/name-generator/
#left, #right {
margin-bottom: 90px;
}
or
#top_section > div {
margin-bottom: 90px;
}
It doesn't work on #top_section because you use absolutes and therefore the content actually over extends the div itself, but trust me, either of those two css' i gave you WILL work
Simply add the following rule:
#top_section {
overflow: hidden;
padding-bottom: 90px;
}
This will make #top_section be as big as the floating content inside it.
http://jsfiddle.net/rlemon/fSYmu/ This is a simplified example, having no idea what your layout looks like (I am not going to assume the demonstration is yours... unless you revise and tell me it is) i'll show you how I would do this
HTML
<div class="container"> <!-- main page wrapper -->
<div class="content"> <!-- main content wrapper, backgrounds apply here -->
<div class="inner-content"> <!-- content inner, where your content goes! -->
content
</div>
</div>
<div class="footer">footer</div> <!-- footer -->
</div>
CSS
​html,body,.container {
height: 100%; margin: 0; padding: 0; // I am important so the page knows what 100% height is.
}
.content {
height: 100%; // see above... i need to cascade down.
background-color: green;
}
.content-inner {
padding-bottom: 100px; // offset for the footer.
}
.footer {
width: 100%;
position: absolute; // stick me to the bottom.
bottom: 0;
height: 100px;
background-color: red;
}
enjoy!
​
You need to use fixed position in CSS to achieve this.
HTML:
<div id="top-section">
Insert content here...
</div>
<div id="bottom-nav">
<div id="content">
Bottom content...
</div>
</div>
CSS:
#bottom-nav {
bottom: 0;
position: fixed;
width: 100%;
}
#content {
margin: 0 auto;
width: 960px;
}

Sticky footer, or rather: content doesn't stretch down to footer

So I wanted a sticky footer on a page and got this one to work for me. All is well, but no, not really..
The problem is that I wanted the content above the footer to stretch all the way down to it. Now the box containing the main content end just after the text in the box, and there's a large space between the footer and the content. What I want is the background of the main content to stretch down to the footer!
See my beautiful image!
This is what I have right now in html:
<div id="wrap">
<!-- start header -->
<div id="header">
<div id="header-content">
</div>
</div>
<!-- end header -->
<!-- start main -->
<div id="main">
<div id="main-content">
</div>
</div>
<!-- end main -->
</div>
<!-- start footer -->
<div id="footer">
</div>
And in css:
html {
height: 100%; }
body {
height: 100%;}
/* wrap */
#wrap {
min-height: 100%; }
/* main */
#main {
background-color: #43145c;
overflow: auto;
padding-bottom: 50px; }
#main-content {
width: 720px;
margin: auto;
background-color: #643280;
padding-top: 20px; }
#footer {
position: relative;
margin-top: -50px;
height: 50px;
clear: both;
background: red; }
I tried setting min height of main to 100%, but didn't work. I just want the backgroundcolor of main-content all the way down to footer, since it's different to the body and main box.
Does it make any sense? Can anyone help?
I know this was asked 6 months ago, but I've been searching for the solution to this problem for quite a while now and hope other people can benefit from the solution I employed being archived. You were spot on when you said that somehow the main box needs to get the min-height of the space between the header and footer.
Unfortunately, I don't know how this can be done with pure CSS, it's quite easy with javascript of course but that solution is not always viable, and it's kind of messy in terms of code separation. The good news is that depending on what you need to do, there is a CSS hack you can employ.
What I did was add an absolutely positioned element below body that essentially stretched from below the header to above the footer.This way I could add a background or a gradient on this #divBelowBody that essentially allowed me to pretend this problem is solved (although this solution leaves a bitter taste in my mouth).
In addition, if you wanted to add a border around your content div and were hoping that it extended to the footer even when content was small, you're screwed (although not really, I can probably think of a hack or two to make this workable), so it only works if you were hoping to add a background or gradient etc.
You can see the code in action here:
http://jsfiddle.net/qHAxG/
Expand the result section horizontally to more clearly see what's going on.
Try this:
Replace your HTML and BODY Styles in the Style Sheet with this:
html,body {height: 100%;}
Then replace your "wrapper" with this:
#wrap {
min-height: 100%;
height: auto;
}
Hope that helps.
Try this
HTML
<body>
<div id="wrap">
<!-- start header -->
<div id="header">
<div id="header-content">
</div>
</div>
<!-- end header -->
<!-- start main -->
<div id="main">
<div id="main-content">
</div>
</div>
<!-- end main -->
<div class="push"></div>
</div>
<!-- start footer -->
<div id="footer">
</div>
</body>
CSS
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
/* wrap */
#wrap {
background: green;
height: auto !important;
margin: 0 auto;
}
#wrap,
#main,
#main-content {
margin-bottom: -50px;
min-height: 100%;
height: 100%;
}
/* main */
#main {
background-color: #43145c;
}
#main-content {
width: 720px;
margin: 0 auto;
background-color: #643280;
}
.push, #footer {
height: 50px;
}
#footer {
position: relative;
background: red;
}​
see THIS demo: it might be of use. It seems like you want a div with a background color to stretch to the bottom. But the problem with the sticky footer is that it stays at the bottom also - get's out of your way when the content extends past the view-port. So It needs some distance ( height of the content ) to know how when to do that. If that height isn't designated by actual content... 100% isn't really going to do the trick either. because then the "sticky" footer doesn't really work... it would be off the screen. What is it really 100% of ?
this whole thing has frustrated me for a year... but I always find a way to make it look the way I want even if I can't get it to function the way I want... hopefully that link demo above will maybe lend another piece to the puzzle. Good Luck !

CSS 100% - 200px?

I'm trying to use <div> objects and CSS to emulate the appearance of frames for a project that I'm working on. Using the following code I was able to properly stretch the list on the left with a border-right, padding, and (if I choose) a background using only one extra element:
HTML:
<div id="sidebar">
<div id="sidebar-content">
<!-- content goes here -->
</div>
</div>
<div id="content">
<!-- more content -->
</div>
CSS:
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#sidebar {
float: left;
height: 100%;
width: 200px;
overflow: auto;
border-right: solid 1px #000;
}
#sidebar-content {
margin: 10px;
padding: 0;
list-style: none;
}
#content {
position: relative;
float: left;
padding: 10px;
}
This worked well until I tried adding another element at the top of the content which stretched horizontally. Here's the current code:
HTML:
<div id="content">
<div id="criteria">
<!-- select boxes -->
</div>
<!-- other content -->
</div>
CSS:
#criteria {
position: absolute;
left: 0;
right: 0;
background: #FF9;
}
This picture shows the results
I tried adding the following rule:
#content {
width: 100%;
}
although this stretched the #content div to the width of the body element, not the body minus the sidebar - so the content appeared below the fold (and beneath the sidebar on the left)
How can I use CSS to stretch the criteria box to fill the content area horizontally?
EDIT -
I wanted to upload a picture of what happened after Karl's recommendation:
Remove the float: left from #content. If there is a floated element next to a normal block element, the block element will fill the remaining space. Also don't set the width attribute.
Here's what happened when float: left was removed
Close, however now the #criteria is stretching to cover up the sidebar. Other suggestions?
Remove the float: left from #content. If there is a floated element next to a normal block element, the block element will fill the remaining space. Also don't set the width attribute.
Edit:
To address the issue of #criteria which is absolutely-positioned forcing itself over to the left, you can add a left-margin to #content to account for the width of the sidebar, as Steven discovered.
As a random sidenote, this would also allow you to keep the content aligned in the case that the sidebar did not take 100% height like it does in Steven's example.
I've used something like this before to get a sidebar layout
sidebar css
    width: 200px;
    z-index:2;
    float: left;
content css
    margin-left: 200px;
    z-index: 1;
    width: 100%;
    padding-right: 2
You can use a similar technique to get a header <div> too.
I might not have got the css exactly correct, but the idea is to use a combination of margin, padding and z-index to get a frames-like effect.
One option would just to have the sidebar and content areas' width based on percentage... say 20% for the sidebar and 80% for the content. I've run into this problem before and just gone with that, but I didn't do too much research on it.

Side-by-side floats

Can two floats be side by side no matter what the width is?
basically I have this below:
#container { height: 100%; width: 100%; overflow: auto; background-color: #F6F9FF; }
#navigation { height: 100%; width: 300px; float: left; overflow: auto; background-color: green;}
#content { float: left; background-color: blue;}
<div id="container">
<div id="navigation">
<ul>
<li>1. nav stuff </li>
<li>1. nav stuff </li>
<li>1. nav stuff </li>
</ul>
</div>
<div id="content">
<p>Lorem ipsum snip....ultricies.</p>
</div>
<div>
I want the navigation and the content to always be side by side. The navigation has an initial width of 300px, however you can close it using jquery and then it only takes up 15pxs. I want the content to always fill the remaining portion of the container. Right now I keep getting it so when the width gets small, the content gets bumped down below the navigation.
Here is a link to jsfiddle to help show what i'm talking about.
http://jsfiddle.net/M9sZd/2/
This is very generic. There are many ways to achieve this, and I'll tell you how I'd do it (with JavaScript, of course). There are two situation: 1. nav extended and 2. nav collapsed. I'd use position: absolute for the navigation, and the corresponding width, while having a padding on the container to accommodate the width of the navigation, and add a class to the container depending on the situation.
#navigation { position: absolute; left: 0; top: 0; width: 300px; }
#navigation.collapsed { width: 15px; }
#container { position: relative; padding-left: 300px;}
#container.nav-collapsed { padding-left: 15px; }
The only risk is that the navigation is higher than the content, and will get trimmed. You can prevent that by using a min-height on the container.
Side by side floating can be tricky sometimes depending on the browser. (I have found issues with IE and using up 100%)
I changed the navigation and content areas to use %-based widths - (20%/80%) and that seemed to easily fit them next to each other.
Link with %-Based Widths
Have you considered using something like a "splitter" to separate the content and navigation and make them adjustable?
jQuery Splitter
I used something like that recently and it really worked for what I was trying to accomplish. You could possibly adjust the widths of the areas explicitly - when you alter the navigation width with something similar to below:
var containerWidth = $("#container").width();
onChange()
{
$("#navigation").css("width", 15px);
$('#content").css("width", containerWidth - 15);
}
Pardon the pseudo-code, it was off the cuff.
Anyways - I hope something here you were able to use :)

Resources