I've been working on a layout for some time. I decided to whip up an example in jsFiddle.
http://jsfiddle.net/PSYgU/1/
The issues I'm running into is that the ASIDE doesn't expand to the full height of it's parent "wrapper", only to the height of the view port. The ASIDE, also needs to be able to be moved to the right or left.
I'm open to other methods of creating this layout, without tables.
/* PHP option to control the width of all content by wrapper via style */
/* PHP option to control which side to float the sidebar to via style */
<div id="wrapper" style="width:100%;">
<aside style="float: right;">This Sidebar</aside>
<header>The Header</header>
<section>The Main Content Area</section>
<footer>The Footer</footer>
</div>
html, body {
min-height: 100%;
height: 100%;
}
#wrapper {
margin: 0;
padding: 0;
background: brown;
height: 100%;
}
aside {
width: 200px;
background: yellow;
height: 100%;
}
header {
height: 150px;
background: blue;
width: 100%;
}
section {
background: red;
width: 100%;
height: 100%;
}
footer {
height: 50px;
background: green;
width: 100%;
}
Because you have section also on height 100% and also lays within the wrapper it wil take the complete height of the wrapper just like sidebar.
example:
when body/html and wrapper have a height of 200px anything within the element wrapper that has height on 100% will have a height of 200px if you add a header within wrapper with height 150px you need to add this to the 200 from before.
this wil result that the height of sidebar never reach the bottom of the wrapper because its missing the height of the header.
a solution to this is to make the header and section together 100% height like header 15% and section 85%.
this will mean that both of them scale but that the sidebar will always be the same height.
<div id="wrapper">
<aside style="float: right;">This Sidebar</aside>
<header>The Header</header>
<section>The Main Content Area</section>
</div>
<footer>The Footer</footer>
html, body {
min-height: 100%;
height: 100%;
}
#wrapper {
margin: 0;
padding: 0;
background: brown;
height: 100%;
width:100%
}
aside {
width: 200px;
background: yellow;
height: 100%;
}
header {
height: 15%;
background: blue;
width: 100%;
}
section {
background: red;
width: 100%;
height: 85%;
}
footer {
height: 50px;
background: green;
width: 100%;
}
Related
I need to create a page where I would have a 100% wrapper between header and footer elements. The wrapper is a general content view where I will be adding templates. Apart of having the wrapper 100% height I need to have a first section in the wrapper also with 100% height.
The main problem is that I cannot position the footer relatively after the wrapper. It stays somewhere in the middle. See fiddle for example.
HTML
<header ui-view="header"></header> <!--Fixed Height/Relative-->
<div id="wrapper" ui-view="wrapper"> <!--100% Height/Relative-->
<section></section> <!--100% Height/Relative-->
<section></section> <!--Auto Height Based On Content/Relative-->
<section></section> <!--Auto Height Based On Content/Relative-->
</div>
<footer ui-view="footer"></footer> <!--Fixed Height/Relative-->
CSS
body{
margin: 0;
padding: 0;
height: 100%;
position: relative;
}
html{
height: 100%;
}
div{
position: relative;
height: 100%;
width: 100%;
}
section:first-child{
height: 100%;
}
section{
position: relative;
display: block;
height: 400px;
width: 100px;
border: 1px solid black;
}
header{
position: relative;
height: 100px; width: 100%; background: red;
}
footer{
position: relative;
height: 100px; width: 100%; background: red;
}
JSFiddle
I believe the div you have around your sections is what's causing you some trouble. Check out the snippet below. If you place only your first section and the header in that div, you can accomplish what you want by putting height 100% on that div.
Note that without that div, your :first-child pseudo selector won't work because that section is no longer the first child of it's parent (header is). So I added an ID to it simply so I can reference it in the CSS.
So now the div is 100% of the height, header is a fixed height, and section1 is at 100% filling the remainder of the div.
body{
margin: 0;
padding: 0;
height: 100%;
background:green;
}
html{
height: 100%;
}
div{
height: 100%;
width: 100%;
background: pink;
}
section {
display: block;
height: auto;
width: 100%;
border: 1px solid black;
}
section#section1 {
height: 100% !important;
}
header{
height: 50px; width: 100%; background: red;
}
footer{
height: 50px; width: 100%; background: blue;
}
<div>
<header></header>
<section id='section1'>section1</section>
</div>
<section>section2</section>
<section>section3</section>
<footer></footer>
The height:100% you have set on the body is what's causing your footer element to be in the middle of the page. Remember that '100%' is '100% of your window height', so be careful with that. Cheers.
I'm using Twitter Bootstrap's 'sticky footer' CSS to ensure my footer appears at the bottom of my page. How can I make my content (the blue div in the example) stretch all the way down to the footer (the yellow div in the example)? I've tried making .content 100% height but that has no effect.
My CSS
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.content {
height: 100%;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
My HTML
<body>
<div class="header">This is my header</div>
<div class="content">This is my content</div>
<div class="footer">This is my footer</div>
</body>
Example: http://jsfiddle.net/pjktqnmo/1/
Ref: http://getbootstrap.com/examples/sticky-footer-navbar/sticky-footer-navbar.css
Update: My header contains my page title so the height of the header varies from page to page.
here is a solution with no position property being used.
see snippet below:
html, body {
height: 100%;
margin: 0;
color:grey;
}
.header {
background-color:red;
}
.content {
min-height: 100%;
margin-bottom: -60px; /* equal to footer height */
background-color:blue
}
.content:after {
content:"";
display: block;
}
.footer, .content:after {
height: 60px;
}
.footer {
background: yellow;
}
<body>
<div class="header">This is my header</div>
<div class="content">This is my content</div>
<div class="footer">This is my footer</div>
</body>
More info here: sticky footer
UPDATED ANSWER Based on a Discussion with OP, where OP stated that doesn't want to have a Vertical ScrollBar, therefore here is a solution below:
What I did? Make your div .header child of div .content, with 0 changes on CSS regarding my 1st snippet above.
html, body {
height: 100%;
margin: 0;
color:grey;
}
.header {
background-color:red;
}
.content {
min-height: 100%;
margin-bottom: -60px; /* equal to footer height */
background-color:blue
}
.content:after {
content:"";
display: block;
}
.footer, .content:after {
height: 60px;
}
.footer {
background: yellow;
}
<div class="content">
<div class="header">This is my header</div>
This is my content
</div>
<div class="footer">This is my footer</div>
If your header is 30px tall, and your footer is 60px tall, this should work for the content:
position: absolute;
left: 0;
right: 0;
top: 31px;
bottom: 61px;
Set the height like this:
html, body {
height: 100%;
}
.content {
min-height: 100%;
}
http://jsfiddle.net/pjktqnmo/6/
It's working pretty well with javascript.
It also allows you to have to good height when user changes window dimensions.
Call this on page load and when user changes the window dimension:
$('.content').css('height',$(document).height() - ($('.header').height() + $('.footer').height() + `MARGIN TOP OR PADDING`) - $('.contact').height());
You could try using a table instead as a container for your page. Make sure that your <html>, <body>, and <table> elements have their width and height at 100%.
Make three rows in your table and put your header, content, and footer into each row, then make the content row 100% height so it will take up the rest of the page space.
Lastly, remove the spacing between the table cells
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.header {
background-color: green;
}
.content {
height: 100%;
background-color: cyan;
}
.footer {
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
html, body {
width: 100%;
height: 100%;
margin: 0px;
}
table {
width: 100%;
height: 100%;
border-spacing: 0px;
}
td {
padding: 0px;
}
.contentCell {
height: 100%;
}
<body>
<table>
<tr>
<td>
<div class="header">This is my header</div>
</td>
</tr>
<tr class="contentCell">
<td>
<div class="content">This is my content</div>
</td>
</tr>
<tr>
<td>
<div class="footer">This is my footer</div>
</td>
<tr>
</table>
</body>
I created a sticky footer, and it appears to be staying at the bottom of the page. The only problem is that when I minimize my browser by dragging the bottom of the browser up, the content above overlaps with the footer. The Content div contains images which are on top of the footer when I minimize. Also the type within the footer appears above the images (when minimized). Any help would be appreciated. Thank you.
<----- HTML Structure ---->
<div class="supercontainer"
<div class="nav"></div>
<div class="wrapper">
<div class="content"></div>
<div class="push"></div>
</div>
</div>
<div class="footer"></div>
<----- Relevant CSS ----->
.supercontainer {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
position: relative;
}
.footer {
background-color: black;
width: 100%;
height: 100px;
}
.push {
height: 100px;
}
To get the content to push down the footer, you need to give the content div a negative bottom margin that matches the footer's height.
.supercontainer {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -100px;
position: relative;
}
.footer {
background-color: black;
width: 100%;
height: 100px;
}
http://css-tricks.com/snippets/css/sticky-footer/
I'm trying to create something like this:
http://jsfiddle.net/S6FUQ/
HTML is:
<div id="container">
<header></header>
<main>
<section class="half"></section>
<section class="half"></section>
</main>
</div>
And CSS is:
* {
margin: 0; padding: 0;
}
html, body, #container {
height: 100%;
}
header {
height: 50px;
background: gray;
}
main {
height: 100%;
background: green;
}
.half {
height: 50%;
}
.half:first-child {
background: blue;
}
.half:last-child {
background: yellow;
}
In it, I have a thin ribbon at the top, and I want to divide the rest of the screen into two equal sections, but I don't want vertical scrollbar to appear.
I tried margin-bottom: 50px; for main, but it didn't work. What should I do?
Height of "main" should be 100% - 50px. Here is the fiddle.
main{height: calc(100% - 50px);}
To make it work on old browsers, you could use absolute positioning.
Demo
#container {
position: relative;
}
main {
position: absolute;
width: 100%;
top: 50px;
bottom: 0;
background: green;
}
You are already using % to set height... Why don't you use it again to solve your problem?
header {
height: 10%;
background: gray;
max-height:50px; //this will ensure your header will never go bigger than 50px
}
main {
height: 90%;
background: green;
}
PS: The only time your header is going to be smaller than 50px is when the browser is smaller than 500px (which will be only in some landscape mobile devices)
EXAMPLE
Here is the JS fiddle I made: http://jsfiddle.net/K6CFU/
The structure is the exact same I'm using for my website but the problem is that I'm not getting the middle section of my site to be 100% high. Right now it's the content that determines how tall it is.
<body>
<div id="page-container">
<header></header>
<div id="page-wrapper">
<div id="page-content">
</div>
</div>
<footer></footer>
</div>
</body>
html, body { height: 100%; padding: 0; margin: 0; }
header { width: 100%; height: 50px; background-color: red; }
footer { width: 100%; height: 50px; position: absolute; bottom: 0; background-color: green; }
#page-wrapper { width: 1024px; margin: 0px auto; background-color: yellow; }
#page-content { height: 100%; background-color: pink; }
Not 100% sure I know what you mean but have you tried adding height:100% to the page-wrapper div?
#page-wrapper{
height:100%;
width: 1024px;
margin: 0px auto;
background-color: yellow;
}
I've ran into this problem in the past. The way that I see it is that when you specify height: 100%;, it fills to 100% of the div (or whatever element) - but not to the screen size. I've always had to use min-height somewhere to get similar results that you're seeking.
For the body or probably for your page-wrapper div, try specifying min-height: 500px; (or whatever you feel is an appropriate size.
Make the page-container
height: 100%;
so that the object inside know the size of the box.
than you can make the page-wrapper
position: absolute;
bottom: 50px;
top: 50px;
height: auto; /*can also be left away*/
now the middle part will be between the footer and the header
http://jsfiddle.net/K6CFU/5/
you can make the page-content
height: 100%;
or you can leave it away, like you want.