I have serious troubles with my css layout.
This is my workingbase: http://jsfiddle.net/UeVm8/1/
<div id="container">
<div id="header">
<h1>
Site name
</h1>
</div>
<div id="content">
<h2>
Page heading
</h2>
<p>
Lorem ipsum dolor sit amet consect etuer adipi scing elit sed diam nonummy nibh euismod tinunt ut laoreet dolore magna aliquam erat volut. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
<p>
Lorem ipsum dolor sit amet consect etuer adipi scing elit sed diam nonummy nibh euismod tinunt ut laoreet dolore magna aliquam erat volut. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
</div>
<div id="footer">
Copyright © Site name, 20XX
</div>
html, body{
margin: 0;
height: 100%;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
padding-top:10px;
padding-bottom:10px;
}
#container
{
position:relative;
margin: 0 auto;
width: 600px;
background:#333;
min-height: 100%;
height:auto !important;
overflow: hidden !important;
}
#header
{
background:#ccc;
padding: 20px;
}
#header h1 { margin: 0; }
#content
{
padding: 20px;
padding-bottom:50px;
}
#footer
{
position:absolute;
background:#ccc;
bottom:0;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
width:100%;
}
The site should always be 100% height at minimum with small distances to top and bottom.
There shouldn't be scrollbars, except the content is too big. Then it should fit to the content and the distances to top and bottom should stay.
But when you resize the window, the padding at the bottom disappears!?!
I already tried different settings and found a solution for Firefox: http://jsfiddle.net/UeVm8/7/
But this solution does not work in Chrome and IE.
I am totally annoyed by this nasty inconsistence in the CSS implementations.
Does anybody know how to solve this issue for all (modern) browsers?
Thanks.
PS: It's an stylesheet only for desktops.
I finally found the answer! :)
As mentioned I already found a solution for Firefox, but it was not working on Chrome.
After some fiddling I also had a solution for Chrome, which wasn't working on Firefox.
I think the issue is that there seems to be a bug in Google Chrome.
But I could combine both solutions by just overwriting settings just for chrome with some special selector.
The CSS solution: http://jsfiddle.net/UeVm8/8/
html, body{
margin: 0;
height: 100%;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
padding-top:10px;
padding-bottom:10px;
}
#container
{
position:relative;
margin: 0px auto 20px;
width: 600px;
background:#333;
min-height: 100%;
height:auto !important;
overflow: hidden !important;
}
#media screen and (-webkit-min-device-pixel-ratio:0) {
#container{
margin: 0px auto 0px;
}
html, body{
overflow:auto;
}
}
#header
{
background:#ccc;
padding: 20px;
}
#header h1 { margin: 0; }
#content
{
padding: 20px;
padding-bottom:50px;
color:grey;
}
#footer
{
position:absolute;
background:#ccc;
bottom:0;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
width:100%;
}
I tested it on Firefox, Chrome, IE, Opera and Maxton and it worked.
Nevertheless CSS is a crazy chick.
Related
I have a two-column layout. The main text on the left, and a sidebar on the right (float: right; width: 30%).
On small browsers, I'd like to first show the main text, and then the sidebar. But if I remove the float from the sidebar with a media query, it shows up first.
I don't want to make the main text another float, because I want it to wrap around the sidebar if the text is long and the sidebar short.
I'm looking for something that's not Javascript if possible.
CSS order Property
When in mobile screen size:
Make the containing tag a flex-container (column wise)
Remove the float related properties from sidebar
Apply order property to the content tag (element with text) and sidebar
The number value of the order property belonging to content tag should be less than the order value of sidebar.
The following demo features:
600px+ Width
Container - <article>
Sidebar - <aside>
float: right
clearfix hack - article::after {...}
Content - <p class="content">
600px Max Width (Mobile)
Container - <article>
flex-container (column)
Sidebar - <aside>
float: none
clearfix hack - removed
order: 3
Content - <p class="content">
order: 2
Demo
Note: View demo in full page mode not in the initial iframe. Resize the window to see the media query work.
:root {
font: 400 3vw/6vh Arial
}
html,
body {
width: 100%;
height: 100%;
padding: 1vh 1vw;
}
main {
width: 90vw;
height: auto;
margin: 5vh -6vw 10vh -6vw;
padding: 3vh 15vw 5vh 5vw;
}
section {
width: 100%;
height: 100%;
}
/*
Begin Sidebar Rulesets
*/
aside {
float: right;
width: 30%;
height: 50%;
border: 3px ridge grey;
margin-left: 3vw;
padding: 5vh 1vw 5vh 2vw;
}
/*
Clearfix hack
*/
aside::after {
content: "";
clear: both;
display: table;
}
/*
End Sidebar Rulesets
*/
header,
footer {
padding: 2vh 0 2vh 0;
margin: 2vh 0;
line-height: 8vh;
}
header {
border-bottom: 5px ridge grey;
}
footer {
border-top: 5px ridge grey
}
h1 {
font-size: 1.75rem;
letter-spacing: 1vw;
margin: 0 0 3vh;
}
h2 {
font-size: 1.45rem;
letter-spacing: 0.75vw;
margin: 0 0 3vh;
}
h3 {
font-size: 1.2rem;
letter-spacing: 0.5vw;
margin: 0 0 3vh;
}
address {
float: right;
font-size: 0.85rem;
margin: 2vh 1vw 5vh 3vw
}
ul {
list-style: none;
padding-left: 1vw
}
li {
margin-bottom: 2vh
}
.content {
font-size: 0.9rem;
line-height: 7vh;
}
/*
Begin Mobile Media Queries
*/
/*
Remove float properties from sidebar (aside)
Convert container (article) into a flex container
Use order property to rearrange how the flex-items appear
(header, p.content, aside)
*/
#media screen and (max-width: 600px) {
article {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
article>header {
order: 1;
}
.content {
order: 2;
}
aside {
float: none;
width: 100%;
order: 3
}
aside::after {
content: none;
}
}
/*
End Mobile Media Queries
*/
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<!-- <link> tags go here -->
<style>
/* CSS Rulesets go here */
</style>
</head>
<body>
<main>
<section>
<header>
<h1>Main Title</h1>
</header>
<!-- Begin Container -->
<article>
<header>
<h2>Topic Title</h2>
</header>
<!-- Begin Sidebar -->
<aside>
<nav>
<header>
<h3>Sidebar Title</h3>
</header>
<hr>
<ul>
<li>
<a href='#/'>Link</a>
</li>
<li>
<a href='#/'>Link</a>
</li>
<li>
<a href='#/'>Link</a>
</li>
</ul>
</nav>
</aside>
<!-- End Sidebar -->
<!-- Begin Content -->
<p class='content'>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae
est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan
porttitor, facilisis luctus, metus</p>
<!-- End Content -->
</article>
<!-- End Container -->
<footer>
<address>
123 Main St.<br>
Springfield, IL 12345<br>
admin#mail.com
</address>
</footer>
</section>
</main>
</body>
</html>
First Solution using float on Desktop and using flex-direction on mobile Will give the result you want.
.sidebar {
float: right;
border: 1px solid;
width: 200px;
}
#media (max-width:767px) {
p,
.sidebar {
float: none;
width: auto;
}
.main {
display: flex;
width: 100%;
flex-direction: column-reverse;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="main">
<div class="sidebar"> <h1>Side bar</h1>
molestiae recusandae placeat corporis earum assumenda dolorem! Earum necessitatibus tempora enim nisi officiis in. Ducimus illo placeat eveniet.</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque explicabo aspernatur delectus voluptate, nesciunt quibusdam ab reprehenderit, non et temporibus. Aut commodi, voluptates nulla deleniti pariatur vitae vel eos sit asperiores aliquid,
molestiae recusandae placeat corporis earum assumenda dolorem! Earum necessitatibus tempora enim nisi officiis in. Ducimus illo placeat eveniet.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque explicabo aspernatur delectus voluptate, nesciunt quibusdam ab reprehenderit, non et temporibus. Aut commodi, voluptates nulla deleniti pariatur vitae vel eos sit asperiores aliquid,
molestiae recusandae placeat corporis earum assumenda dolorem! Earum necessitatibus tempora enim nisi officiis in. Ducimus illo placeat eveniet.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque explicabo aspernatur delectus voluptate, nesciunt quibusdam ab reprehenderit, non et temporibus. Aut commodi, voluptates nulla deleniti pariatur vitae vel eos sit asperiores aliquid,
molestiae recusandae placeat corporis earum assumenda dolorem! Earum necessitatibus tempora enim nisi officiis in. Ducimus illo placeat eveniet.</p>
</div>
</div>
Helping Credits goes to #zer00ne
Second Solution if not using text to wrap under sidebar Using flex we can achieve this. As it has many advantages of playing with its properties without changing HTML structure and its more mature then float
.flex-container {
display: flex;
flex-direction: column;
}
.main {
width: 100%;
order: 1;
padding: 0 1em;
}
.sidebar-aside {
width: 100%;
order: 2;
padding: 0 1em;
background-color: #cff;
}
#media (min-width: 40em) {
.flex-container {
flex-direction: row;
}
.main {
flex: 1;
order: 1;
}
.sidebar-aside {
width: 15em;
order: 2;
}
}
<div class="flex-container">
<main class="main">
<article>
<h1>Main Title</h1>
<p>Some Content to fill the page.</p>
<h2 id="topic-1">Topic 1</h2>
<p>Info</p>
<h2 id="topic-2">Topic 2</h2>
<p>Info</p>
<h2 id="topic-3">Topic 3</h2>
<p>Info</p>
</article>
</main>
<aside class="sidebar-aside">
<h3>Side Bar</h3>
<h4>Sidebar Title</h4>
<p>Lorem epsum text is a dummy text</p>
</aside>
</div>
You can change the order on different screens that which div comes
first
It can be achieved using css grid
/* Here 2fr for main text and 1fr for side bar */
grid-template-columns: 2fr 1fr;
For screen size 600px or less
/* For mobile devices, it will be 1/1 grid */
grid-template-columns: 1fr;
*{
padding: 0;
margin: 0;
}
.container{
background: #f2f2f2;
padding: 10px;
height: 100vh;
}
.layout{
display: grid;
/* Actual style width 2 grid layout */
grid-template-columns: 2fr 1fr;
padding:5px;
}
.main-text{
padding: 20px;
}
.side-bar{
border: 2px solid #444;
}
/* For mobile devices with 1f 1/1 grid */
#media (max-width:600px){
.layout{
grid-template-columns:1fr;
}
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="container">
<h3>Resize screen for responsive</h3>
<div class="layout">
<div class="main-text">
<h2>Main text</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ultrices mollis cursus. Vestibulum aliquam, lorem quis porta sodales, diam mi tincidunt quam, vitae consequat erat neque in turpis. Nam massa libero, feugiat ut laoreet eu, interdum et erat. Morbi quis suscipit nunc, blandit congue sapien. Aenean faucibus nisi sit amet quam interdum, eget mollis enim rutrum. Etiam viverra vel magna quis rutrum. Maecenas ipsum urna, feugiat sed sagittis id, vehicula eu enim. Ut commodo odio vitae nibh posuere blandit. Nunc aliquam metus vitae vehicula tempus. Vivamus semper pharetra felis mollis pellentesque. Vestibulum quis velit feugiat, blandit tortor a, mattis turpis. Mauris varius nisl id ultricies tempus. Vivamus imperdiet euismod pellentesque. Nullam pretium elit id semper convallis.
</div>
<div class="side-bar">
<h2>Side bar</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ultrices mollis cursus. Vestibulum aliquam, lorem quis porta sodales, diam mi tincidunt quam, vitae consequat erat neque in turpis. Nam massa libero, feugiat ut laoreet eu, interdum et erat. Morbi quis suscipit nunc, blandit congue sapien. Aenean faucibus nisi sit amet quam interdum, eget mollis enim rutrum. Etiam viverra vel magna quis rutrum.
</div>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
<style>
body {
font-family: sans-serif;
}
.app {
display: flex;
justify-content: flex-start;
align-items: stretch;
}
.main-text {
flex-basis: 70%;
background-color: #ddd;
min-height: 200px;
}
.sidebar {
flex-basis: 30%;
background-color: #1a1a1a;
color: white;
min-height: 100px;
}
#media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
.app {
flex-wrap: wrap;
}
.main-text {
flex-basis: 100%;
}
.sidebar {
flex-basis: 100%;
}
}
</style>
</head>
<body>
<div class="app" id="app">
<div class="main-text">
Main Text
</div>
<div class="sidebar">
SideBar
</div>
</div>
</body>
</html>
simple solution using flexbox, no javascript involved
class main-text and sidebar refer to respective components
height and background colors are added just for the visual effect,they are not necessary for the solution to work
Flexbox solution:
html:
<div class='content'>
<div class='main'><p> lorem ipsu... </p></div>
<div class='sidebar'><p> lorem ipsu ... </p></div>
</div>
css:
.container{
display: flex;
flex-wrap: wrap;
}
.main{
order: 1;
width:70%;
}
.sidebar{
order:2;
width:30%;
}
#media (max-width:600px){
.main{
width:100%;
}
}
Idea is that the main simply takes up the full width, forcing the sidebar down below it.
I'm in the process of developing a blog and am trying to achieve a hover effect that slides up to reveal the full post preview on hover. The attached image is probably better at conveying the desired effect. Basically, only the title of the post is shown, then on hover the title slides up, also revealing the rest of the preview.
The only way I've been able to come close so far is by using two seperate div's, one with just the title and the other with the full preview (title included). Then fade the title div out while sliding the other up. It looked okay but it's just not as smooth as I'd like it to be. I would much prefer everything to slide up.
If any CSS wizards can help me, I'd appreciate it. Also, CSS-only would be great, JS as a last resort.
Thanks,
Oli.
Here's a quick / dirty solution:
HTML:
<div class="container">
<div class="post">
<div class="title">Bla bla bla</div>
<div class="body">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</div>
CSS:
.container {
background-color: #00f;
width: 300px;
height: 300px;
position: relative;
}
.post {
cursor: pointer;
background-color: #fff;
position: absolute;
bottom: 20px;
left: 20px;
right: 20px;
}
.body {
transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
height: 0;
opacity: 0;
overflow: hidden;
}
.post:hover .body {
height: 200px;
opacity: 1;
}
DEMO: https://jsfiddle.net/y7rb77sk/
Of course you can add transitions to animate it and make it cooler
Here is a solution: http://jsfiddle.net/leojavier/gbuLykdj/4/
Incase of overflow, this solution will give you a scroll: http://jsfiddle.net/leojavier/gbuLykdj/5/
<div class="container">
<img src="http://placecorgi.com/300/400" alt="">
<article>
<h1>My Title</h1>
<p>san leo vestibulum non. Donec porttitor semper malesuada. Morbi vel felis venenatis, tempus mi in, ornare purus. Morbi hendrerit orci ipsum, a fringilla ante tristique in. Fusce sollicitudin venenatis neque eget ornare. Integer semper, ante ut vestibulum finibus, ipsum ex aliquam quam, qui</p>
</article>
</div>
CSS
.container{
position:relative;
width:300px;
height:400px;
}
article{
position:absolute;
width:100%;
max-width:280px;
height:auto;
background:rgba(255,255,255,0.8);
bottom:0;
padding:10px;
font-family:arial;
opacity:0;
transition: opacity 1s;
}
.container:hover > article {
opacity:1;
}
I've been searching for an answer on this, and tried multiple methods of fixing it to no avail. I'm teaching myself CSS while re-building a site, and have a small problem.
I have a container within a parent container - the "sub-container" (for lack of a better term) has it's own header, a photo to the left, and copy to the right. The copy should be top-aligned to the photo, and equally spaced between the right edge of the photo and the right edge of the background image in the sub-container. What I'm getting is the photo in the proper place, with the copy butted up against the bottom right corner of the photo.
I'm fairly certain the issue is a mix between lack of knowledge and a mis-understanding of what is causing what... so any help with this is greatly appreciated.
Here's my CSS:
#wrapper {
background-image:url("images/About/Copy-Block.png");
background-repeat:no-repeat;
width: 745px;
height: 339px;
margin: 0 auto;
margin-top: 30px;
}
#wrapper head {
display:block;
padding-top: 15px;
padding-bottom: 2px;
}
#wrapper photo {
float: left;
}
.wrapcopy {
padding-left: 90px;
font-size: 13px;
color: #FFF;
}
and here is my html:
<div id="wrapper">
<div id="wrapper head" align="center">
<img src="images/About/About-Us-Subhead.png" width="748" height="116" />
</div>
<div class="wrapcopy">
<img src="images/About/image.png" width="257" height="194" class="wrapper photo"/>
<i>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</i>
</div>
</div>
You wrote "photo" instead of "img" in your CSS, edit it like this and it will work!
#wrapper img{
float: left;
}
However, you have 2 images in your example and this will float both of them. You can solve that by giving for example an ID/class to those images.
First off, you aren't referencing your classes properly: "#wrapper photo" should be "#wrapper .photo". Also, id's can't have spaces in them ("#wrapper head").
There are a few ways you can add spacing you desire. The most straight forward way would be to add padding directly to the image:
#wrapper .photo { float: left; padding-right: 10px }
I would also like to point out that the markup you are using is very poor. Headlines should go in h1-h6 tags (images are still allowed in these tags!), paragraphs of text should be in p tags. Section or article tags might be an appropriate replacement for your wrapper div. It's not enough to know CSS, you also need to know the appropriate HTML markup to go with it.
A more efficient way of doing this would be like this:
section.foo {
background-image:url("images/About/Copy-Block.png");
background-repeat:no-repeat;
width: 745px;
height: 339px;
margin: 0 auto;
margin-top: 30px;
}
section.foo h1 {
padding-top: 15px;
padding-bottom: 2px;
text-align: center;
}
section.foo p {
padding-left: 90px;
font-size: 13px;
color: #FFF;
font-style: italic;
}
section.foo p img {
float: left;
padding-right: 10px;
}
And the HTML:
<section class="foo">
<h1><img src="images/About/About-Us-Subhead.png" width="748" height="116" /></h1>
<p><img src="images/About/image.png" width="257" height="194" /> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</section>
First of all, Never use any spaces naming an ID.
So change id="wrapper head" to id=id="wrapper_head"
Next, elements can be selected by their tags.
An Image is coded by <img tag so you can select it directly in CSS by img { } .
In your case, you want to select image inside #wrapper division, so select it by :
#wrapper img
{
/* Code Here... */
}
The problem of your code are the spaces in the id tags.
Try something like
<div id="wrapper_head" ....
instead of
<div id="wrapper head" ....
That should solve your problem!
I know this question has probably been asked before and I have tried several different ways of doing this, but I can not seem to get my inner DIV to expand to the full height of the viewport.
Here is my CSS:
html, body {margin: 0 auto; padding: 0; height: auto !important; min-height: 100%; height: 100%;}
p, h1 {font-family:"lucida grande",tahoma,verdana,arial,sans-serif;font-size:11px;text-align:left;margin:1em 0}
/*******************************************************************************
Primary Container Structure
********************************************************************************/
#container {width: 100%; margin: 0px 0px; background-color: #fff; color: #333;}
#top {padding: .5em; background-color: #3b5998; color:White;}
#top h1 {padding: 0; margin: 0;}
#subcontainer {width: 90%; margin: 0px auto; line-height: 130%;}
#rightnav {height:100%; float: right; width: 244px; margin: 0; padding: 1em; max-width:244px;}
#content {height:100%; border-left: 1px solid gray; margin-right: 284px; border-right: 1px solid gray; padding: 1em;}
#leftnav p, #rightnav p {margin: 0 0 1em 0;}
#content h2 {margin: 0 0 .5em 0;}
#footer {clear: both; margin: 0; padding: .5em; color: #333; background-color: #ddd; border-top: 1px solid gray;}
Here is my HTML:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="SHELL.aspx.cs" Inherits="SHELL" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="css/base.css">
</head>
<body>
<form id="form1" runat="server">
<div id="container">
<div id="top">
<h1>NAME</h1>
</div>
<div id="subcontainer">
<div id="rightnav">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.
</p>
</div>
<div id="content">
<h2>Subheading</h2>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
<p>
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p>
</div>
</div>
<div id="footer">
Footer
</div>
</div>
</form>
</body>
</html>
You cannot have a middle container first calculate a footer height, then subtract it from it's 100% height parent container.
You're only options with your current markup are:
Use javascript (unncessary overhead)
Use tables (probably not a good idea)
Here is an option that I had to rearrange your code: Code Here
I made your height and footer work, but it will require you to use faux columns, a common technique for bottom sticking footers. See this for an example.
Simply, assign a left border image to repeat-y on the body, and a right border image to repeat-y, background right, on the subcontainer.
I've got a basic site with header, content, footer. What I'm looking for is a way to style the footer so that, depending on screen resolution, if the content doesn't fill the page it sticks to the bottom, but if content overflows it pushes the footer down (have to scroll the browser to see the footer).
<div id="wrapper">
<div id="headwrapper">
<div id="header"></div>
<div id="menu">
<ul>
<li class="active">Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
<li>Link5</li>
</ul>
</div>
<div id="content-container">
<div id="content">
<h2>
Page heading
</h2>
<p>
Lorem ipsum dolor sit amet consect etuer adipi scing elit sed diam nonummy nibh euismod tinunt ut laoreet dolore magna aliquam erat volut. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
<p>
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p>
<p>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p>
</div>
<div id="aside">
<h3>
Aside heading
</h3>
<div class="box">
<p>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan.
</p>
</div>
<div class="box">
<p>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan.
</p>
</div>
</div>
</div>
</div>
<div id="footer">
<p>Footer content</p>
</div>
</div>
html, body {height:100%;}
#wrapper {
max-width:100%;
min-width:1000px;
min-height:100%;
margin:0 auto;
background-image:url(images/shadowborder.png);
background-repeat:repeat-y;
background-position:center;
}
#headwrapper {
position:relative;
-moz-background-clip:border;
-moz-background-origin:padding;
-moz-background-size:auto auto;
background-attachment:scroll;
background-color:#003a72;
background:url(images/bnr_rpt.jpg) repeat-x;
height:150px;
}
#header {
position:relative;
-moz-background-clip:border;
-moz-background-origin:padding;
-moz-background-size:auto auto;
background-attachment:scroll;
background-color:transparent;
background:url(images/KMIAFS_banner.jpg) center top no-repeat;
height:150px;
}
#menu {
clear:left;
float:left;
padding:0;
border-top:5px solid #f52620;
width:100%;
overflow:hidden;
height:70px;
}
#menu ul {
float:left;
margin:0;
padding:0;
list-style:none;
position:relative;
left:50%;
text-align:center;
}
#menu ul li {
display:block;
float:left;
list-style:none;
margin:0;
padding:0;
position:relative;
right:50%;
font-size:16px;
font-family:Verdana, Geneva, sans-serif!important;
font-weight:bold;
}
#menu ul li a {
display:block;
float:left;
margin:0 2px 0 0;
padding:10px 20px 6px 20px;
background:#003a72;
text-decoration:none;
color:#FFF;
}
#menu ul li a:hover {
padding:15px 20px 6px 20px;
background-color:#999;
}
#menu ul li.active a, #menu ul li.active a:hover {
color:#CCC;
}
#content-container {
min-height:100%;
height:100%;
height:auto!important;
margin:0 auto -70px;
width:1000px;
}
#content {
clear:left;
float:left;
width:610px;
margin:0 0 0 30px;
display:inline;
background-color:transparent;
}
#content img {
border:solid 2px #CCC;
float:left;
margin:14px 10px 10px 0px;
}
#content h2 {
margin:0;
}
#aside {
float:right;
width:290px;
margin:0 30px 0 0px;
display:inline;
background-color:transparent;
}
#aside p {
color:#CCC;
}
#aside .box {
margin-bottom:20px;
padding:20px;
color:#fff;
background-color:#336699;
-webkit-border-radius:20px;
-moz-border-radius:20px;
}
#footer {
height:70px;
width:100%;
border-top:5px solid #f52620;
background:url(images/ftr_rpt.jpg) repeat-x;
text-align:center;
color:#FFF;
margin:0 auto;
clear:both;
}
#footer a {
color:#FFF;
text-decoration:none!important;
padding:-5px;
}
#footer a:hover {
color:#CCC;
}
And here's the site: http://www.erisdesigns.net/Stage/McCampbellInsurance/index.html
I use this version, and it works quite well.