Setting the min-height of a div within the zurb-foundation - html

I've just been introduced to the Zurb Foundation 4 framework via a friend of mine. Interesting stuff. But i'm having a problem I can't seem to understand. I have a site based on 4 rows (header, navbar, content, footer);
<div class="row siteBase">
<div class="row siteHeader" id="siteHeader">
<div class="large-12 c7olumns">
<h2>Welcome to Foundation</h2>
<p>This is version 4.1.2.</p>
</div>
</div>
<div class="row siteNavbar" id="siteNavbar">
navbar
</div>
<div class="row siteBody" id="siteBody">
base
</div>
<div class="row siteFooter" id="siteFooter">
footer
</div>
</div>
here's my CSS
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.siteBack {
background-color: #545454;
}
.siteBase {
/*base size and color*/
width: 1280px;
min-height: 100%;
margin: 0 auto;
background-color: #f2f2f2;
/* exact fit the contents to the border */
padding-left:15px;
padding-right:15px;
/* border size and color */
border-style: solid;
border-left-width: 4px;
border-top-width: 0px;
border-right-width: 4px;
border-bottom-width: 0px;
border-color: #7da500;
/* add some shadows to the borders */
-moz-box-shadow: 0 0 10px 5px #272727;
-webkit-box-shadow: 0 0 10px 5px #272727;
box-shadow: 0 0 10px 5px #272727;
}
.siteHeader
{
width: 100%;
height: 250px;
background-color: #7da500;
}
.siteNavbar
{
height: 50px;
background-color: #1d1d1d;
}
.siteBody
{
min-height: 100% auto;
margin: 0 auto;
background-color: #f2f2f2;
}
.siteFooter
{
height: 50px;
background-color: #7da500;
}
The problem I have is that the sitebody div isn't stretched to to full 100%. The header and navbar is fixed size, as is the footer. But I wan't the sitebody div to take the remaining space so that the footer is always placed in the lower bottom of the screen (at minimum).
What am I missing here? Thanks a lot for your help.

Basically what you need is to stick your footer to the bottom of the page. In that manner you will have a full body even if your main content is small. You can take a look at this SO question to see how it is implemented. There could be a lot going on in there as that layout is a bit complex. So I did a sample for you that you can use for a more simple layout. Here is the modified css from the other SO question.
html, body, #wrapper{ height: 100%; }
body > #wrapper{height: auto; min-height: 100%;}
#main { padding-bottom: 75px; /* same height as the footer */
overflow:hidden;
top: 75px; bottom: 0; left: 0; right: 0;
background-color:yellow;
}
#footer {
position: relative;
margin-top: -75px; /* negative value of footer height */
height: 75px;
clear:both;
}
.clearfix:after {content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;}
.clearfix {display: inline-block;}

Related

How to make one div fill all horizontal space

I'm new to html and css, and while I was creating a page for training, I made one div to fill the top horizontal space.
However I did not have succsess in doing that, and I have no idea why, I tried tweaking the margins, the padding, looked around on the internet and found no solution for my case. I wanna know if it is possible to fill all horizontal space with only one div.
Here is how my code currently is looking:
#charset "UTF-8";
#import url('https://fonts.googleapis.com/css?family=Orbitron');
body{
background-color: green;
color: green;
font-family: 'Orbitron', sans-serif;
overflow-x: hidden;
}
div#page{
width: 900px;
height: 900px;
background-color: black;
box-shadow: 1px 1px 500px rgb(0,0,0);
padding: 10px;
margin: 0px auto 0px auto;
}
div#pageHead {
width: 102%;
background-color: rgb(20,20,20);
height: 70px;
position: relative;
margin: -8px 0px auto 0px;
}
<div id="pageHead">
<header></header>
</div>
<div id="page">
<header>
this is a test
</header>
</div>
Just apply margin:0 to the body tag. You are getting the default margin from the body.
body{
background-color: green;
color: green;
font-family: 'Orbitron', sans-serif;
overflow-x: hidden;
margin:0;
}
div#page{
width: 900px;
height: 900px;
background-color: black;
box-shadow: 1px 1px 500px rgb(0,0,0);
padding: 10px;
margin: 0px auto 0px auto;
}
div#pageHead {
width: 102%;
background-color: rgb(20,20,20);
height: 70px;
position: relative;
margin: -8px 0px auto 0px;
}
<div id="pageHead">
<header></header>
</div>
<div id="page">
this is a test
</div>
Try this
body{ margin :0; background-color: green;color: green; font-family: 'Orbitron', sans-serif; overflow-x: hidden;}
A div by default takes up as much horizontal space as possible. So it is generally as wide as its parent element.
As I understand your problem you are missing the the last few pixels on either side. This is not an issue of the div, but of the body element. The body element has to a default margin.
So you have to set the body margin to 0 (zero). Then you can either not specify a width for the div or give the div a width of 100%.
Then the div should take up the whole horizontal space of the webpage.
First problem, your page div is not valid (closed tag that is never opened).
For the width, add
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
to reset browser styles.
https://jsfiddle.net/dtz5h9yh/3/
#charset "UTF-8";
#import url('https://fonts.googleapis.com/css?family=Orbitron');
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background-color: green;
color: green;
font-family: 'Orbitron', sans-serif;
overflow-x: hidden;
}
div#page{
width: 900px;
height: 900px;
background-color: black;
box-shadow: 1px 1px 500px rgb(0,0,0);
padding: 10px;
margin: 0px auto 0px auto;
}
div#pageHead {
width: 102%;
background-color: rgb(20,20,20);
height: 70px;
position: relative;
margin: 0;
}
<div id="pageHead">
<header></header>
</div>
<div id="page">
<header>
this is a test
</header>
</div>
Add this to your CSS:
*{
margin:0;
padding:0;
}
div#page{
width:100%;
}
Also remove the </header> from the div with id"page".
hope this helped

CSS Sticky Footer - Getting content border to extend to the footer

I know that there are tons of questions about this but I've been searching Google for 4 days now and nothing is seeming to work for me. I'm trying to implement a sticky footer - meaning that when there is not enough content to fill the screen, the footer is at the bottom of the screen and when there is enough content to fill the screen, the footer stays below that content and you scroll down.
I have tryed roughly 15 different sticky footer solutions and while most of them work in theory, my particular situation keeps messing it up my content has borders on the left and right that should extend down to the footer. Anything involving push won't work.
Here is the most recent incarnation of what I've tried:
HTML
<div id="container">
<div id="header">
<!--Banner goes here-->
<div id="nav">Navigation Links</div>
</div>
<div id="content">
<p>Content Goes Here</p>
</div>
<div id="footer">
</div>
</div>
CSS
html, body {
padding: 0;
margin: 0;
height: 100%;
}
#container {
min-height: 100%;
position: relative;
}
#content {
padding: 20px;
border-left: solid 30px lightblue;
border-right: solid 30px lightblue;
}
#footer {
position: absolute;
bottom: 0;
width: 100%;
height: 80px;
border-top: solid;
text-align: center;
padding-top: 10px;
}
How do I get this sticky footer to work while also getting those blue borders to extend down to the footer?
Here's a solution that uses box-shadow to create the "border:" http://jsfiddle.net/FT8KR/. The pixel values were rather arbitrary, so play with those. Border can also be used, but it pushes the scroll bar more inwards, whereas box-shadow naturally does not.
#container {
height: 100%;
margin: 0 auto -80px;
overflow: auto;
padding-bottom: 80px;
padding: 0 30px;
box-shadow: inset -48px 0 0 lightblue,
inset 30px 0 0 lightblue;
}
body{
padding-bottom: 90px
}
#footer {
position: absolute;
bottom: 0;
left: 0;
right:0 ;
height: 80px;
border-top: solid;
text-align: center;
padding-top: 10px;
}

DIV 100% within DIV, keeping footer sticky

Goals:
"page-wrap" (blue background) must extend height of entire page.
Also keep footer at bottom of page.
Footer cannot overlap sidebar/content.
Problem:
Adding height:100% to #container causes footer to overlap when window resized, and adds blank space under footer caused by header
I've tried dozens of different configurations, but cannot seem to reach my goals.
http://jsfiddle.net/fZmut/3/
<div id="container">
<div id="header">header</div>
<div id="page-wrap">
<div id="inside">
<div id="sidebar">
<p>sidebar</p>
<p>sidebar</p>
<p>sidebar</p>
<p>sidebar</p>
</div>
<div id="flow-content">
<p>content</p>
<p>content</p>
<p>content</p>
<p>content</p>
</div>
</div>
<div id="footer">footer</div>
</div>
</div>
css
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
/* height:100%; */ /* causes footer to overlap when window resized, and adds blank space under footer caused by header */
min-height: 100%;
position:relative;
margin: 0px auto 10px;
background-color: black;
}
#header{
background-color:green;
width:100%;
border-bottom: 2px solid black;
}
#page-wrap {
background: blue;
width: 450px;
margin: 0px auto 10px;
height:100%;
}
#page-wrap #inside {
margin: 0px 10px 0px 10px;
padding-top: 10px;
padding-bottom: 20px;
}
#sidebar {
width: 50px;
float: left;
padding-left: 0px;
padding-top: 0px;
background-color: gray;
}
#flow-content {
background-color: yellow;
padding-left: 50px;
padding-top: 1px;
padding-right: 15px;
}
#footer {
background: #fff;
border: 1px solid black;
height: 20px;
width: 430px;
margin: 0 10px;
bottom: 0;
position: absolute;
}
You Can add 100% to #container and resolve the 2 issues you mentioned:
make the header absolute position to take care of the extra height issue. (but then you'll need to add extra padding to the blue area to accomodate.
also Make the footer display like a table row and its parent table to take care of the overlapping issue:
#header{
background-color:green;
width:100%;
border-bottom: 2px solid black;
**position:absolute;**
}
#page-wrap {
background: blue;
width: 450px;
margin: 0px auto 10px;
height:100%;
**display:table;
padding-top:20px;**
}
#footer {
background: #fff;
border: 1px solid black;
height: 20px;
width: 430px;
margin: 0 10px;
**display:table-row**
}
http://jsfiddle.net/fZmut/7/

Horizontal scrollbar bug when minimising window

I'm encountering some difficulty with some CSS I'm coding.
Whenever I minimise the window a horizontal scrollbar appears and the problem with this scrollbar is that it doesn't go away even when I maximise the window.
What could I be doing wrong?
Thanks in advance
CSS
body {
background-color: #C5C5C5;
margin-left: 0px;
margin-top: 0px;
}
html {
overflow-y: scroll;
}
.header_bg {
background-color: #F1F1EE;
padding: 10px 10px 10px 10px;
border-top: 2px solid #738ebe;
width: 100%;
}
.header_main {
width: 960px; // would it be better to change this to width: 80%
margin:0 auto;
overflow: hidden;
}
.header_main img {
float: left;
}
.header_main div {
float: right;
}
HTML
<div class="header_bg">
<div class="header_main">
<img src="resources/img/login_logo.png" width="163" height="66" />
<div>Already a member? Sign in</div>
</div>
</div>​
This:
.header_bg {
background-color: #F1F1EE;
padding: 10px 10px 10px 10px;
border-top: 2px solid #738ebe;
width: 100%;
}
Is adding to the calculated width of it's container, ie, body, which header_bg is stretching to fit 100%, so the padding is shifting bodys dimensions beyond the viewport, thus triggering scroll-x.
Remove it and your scroll bar goes away:
padding: 10px 0;
Edit: http://jsfiddle.net/userdude/782fc/2/
Full: http://jsfiddle.net/userdude/782fc/2/embedded/result
Or, alternatively, put the width on the body with margin: 0 auto; so it auto-centers:
body {
background-color: #C5C5C5;
width: 1024px;
margin: 0 auto;
}
...
.header_bg {
background-color: #F1F1EE;
padding: 10px;
border-top: 2px solid #738ebe;
width: 100%;
}
.header_main {
width: 100%;
margin:0 auto;
overflow: hidden;
}
Edit: http://jsfiddle.net/userdude/782fc/4/
Full: http://jsfiddle.net/userdude/782fc/4/embedded/result/

HTML + CSS: take all available viewpoer

I'm trying to make liquid HTML layout with header (taking all available width and 130px height), 2 columns (1: 300px width all possible height, 2: all available width after column 2 took its 300px and 15-20px margin between them).
Atm I've got this:
HTML:
<div class="wrapper">
<div class="header">
<!-- .... -->
</div>
<div class="content">
<div class="left-column">
<!-- ... -->
</div>
<div class="right-column">
<!-- ... -->
</div>
</div>
</div>
CSS:
html, body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
min-width: 1000px;
min-height: 500px;
}
body {
font: 12px sans-serif;
background-color: #fff;
color: #000;
}
.wrapper {
height: 100%;
width: 100%;
position: relative;
}
.header {
padding: 0 30px;
height: 100px;
left: 0px;
right: 0px;
position: absolute;
border: 1px solid black;
border-top: none;
}
.content {
position: absolute;
top: 120px;
left: 0;
right: 0;
bottom: 0px;
margin: 10px 20px;
border: 1px solid black;
}
.left-column {
float: left;
width: 300px;
border: 1px solid black;
}
.right-column {
margin-left: 315px;
border: 1px solid black;
}
The question is: are there any better solutions?
Thanks.
I took your HTML and created this fiddle for you: http://jsfiddle.net/RdQJY/1/. I didn't use any of your CSS though - I just don't like positioning used in the way you are using it, so decided to write it from scratch (sorry about that). The lorem ipsum text is just there as a placeholder - if you remove it, you'll see that the divs will occupy the whole window. Hope this helps!
P.S.: the only drawback to my method of having equal-height columns is that there is no easy way to apply a bottom border to them.