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/
Related
Here is my code taken from the codepen: http://codepen.io/rags4developer/pen/ONoBpm
Please help me to fix these problems.
How do I prevent the the main div & footer from spilling out of the container div ? overflow: hidden for container will not always work !
How do I make the container div height equal to page height without setting its height to a fixed percentage ?
HTML:
<body>
<div id="container">
<div id="nav">nav links 1,2,3 etc</div>
<div id="main">
<!--no text here-->
<div id="left">left panel</div>
<div id="right">right panel</div>
</div>
<div id="footer">footer</div>
</div>
</body>
CSS:
* {box-sizing: border-box;}
html {height: 100%;}
body {height: 100%;}
#container {
border: 8px solid yellow;
height: 100%;
width: 80%;
margin: 0 auto;
}
#nav {
border: 4px solid red;
height: 15%;
}
#main {
border: 4px solid black;
height: 100%;
background: gray;
}
#left {
border-top: 4px solid green;
border-left: 4px solid green;
border-bottom: 4px solid green;
float: left;
width: 15%;
height:100%;
/*I will make this gradient later*/
background: #9e9999;
}
#right {
border: 4px solid blue;
float: right;
width: 85%;
height: 100%;
border-radius: 20px 0 0 0;
background: white;
}
#footer {
border: 4px solid pink;
clear: both;
}
I am not completely sure if I understand you correctly, but your heights (i.e. the heights within the #container div) add up to 15% + 100% + the height of the footer = at least 115% of the #container height plus the footer height, which causes the "spilling over".
I changed the #content height to 80% and added height: 5%; to the footer in this fork of your codepen: http://codepen.io/anon/pen/EKeOdm
Now everything remains within the #container. Is this what you want?
The clearfix solution still works well for floated elements, IMO. Try removing the height styles and add this:
#main:before,
#main:after {
display: table;
content: "";
}
#main:after {
clear: both;
}
Further: http://nicolasgallagher.com/micro-clearfix-hack/
Using display table should fix this.
#container {
border: 8px solid yellow;
height: 100%;
width: 80%;
margin: 0 auto;
**display: table;**
}
#content {
border: 4px solid black;
background: gray;
height: 100%;/*Not sure 100% of what ? Parent ???*/
**display: table-row;**
}
I created a container. Plain text in the container displays inside the container, however, formatted text displays outside of the container. Please give suggestions. My html and css are posted below.
This is my html:
.left-column {
text-align: left;
float: left;
width: 40%;
padding-left: 5px;
}
.right-column {
text-align: left;
float: left;
width: 50%;
padding-left: 200px;
}
#container {
width: 900px;
background-color: #ffffff;
border: 1.5px solid #FFCC99;
margin: 0;
padding: 10px;
}
.border1 {
width: 910px;
border: 3px solid #376092;
margin: 1px;
padding: 2px;
}
border2 {
width: 915px;
border: 2px solid #FFCC99;
margin: 12px auto 12px auto;
}
<main id="gap">
<div class="border2">
<div class="border1">
<div id="container">
<div class="left-column">
</div>
<div class="right-column">
</div>
</div>
<!-- End Container -->
</div>
<!-- End Border1 -->
</div>
<!-- End Border2 -->
</main>
because you are floating the .left-column and .right-column, you should use a clearfix
Also I would advise you to use box-sizing:border-box, see more about border box model
Here is a snippet:
.cf:before,
.cf:after {
content: " ";
display: table;
}
.cf:after {
clear: both;
}
*, *:before, *:after {
box-sizing: border-box;
}
.left-column {
text-align: left;
float: left;
width: 40%;
padding-left: 5px;
}
.right-column {
text-align: left;
float: left;
width: 50%;
/*padding-left: 200px; - this can be removed */
}
#container {
width: 900px;
background-color: #ffffff;
border: 1.5px solid #FFCC99;
margin: 0;
padding: 10px;
}
.border1 {
width: 910px;
border: 3px solid #376092;
margin: 1px;
padding: 2px;
}
.border2 {
width: 915px;
border: 2px solid #FFCC99;
margin: 12px auto 12px auto;
}
<main id="gap">
<div class="border2">
<div class="border1">
<div id="container" class="cf">
<div class="left-column">text left</div>
<div class="right-column">text right</div>
</div>
<!-- End Container -->
</div>
<!-- End Border1 -->
</div>
<!-- End Border2 -->
</main>
Set overflow:hidden in #container. This will force the container to respect the height of all elements within it, regardless of floating elements.
CSS
#container {
width:900px;
background-color: #ffffff;
border:1.5px solid #FFCC99;
margin: 0;
padding:10px;
overflow: hidden; /* Set this rule */
}
DEMO HERE
The problem is your padding on your #container.
Your css is :
padding: 10px and width: 910px
So, your padding add 20px (10px right, 10px left).
In the end, your #containter width is 920px and your parent div is 910px.
To fix your problem, you need to set the width of your parent to 920 or change the padding to : padding:5px;
I have a header element in a header div but for some reason i can't seem to add any bottom margin or padding to it. Margin/padding top, left, and right work find however. is there a reason for this? here is my code.
html
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
</div>
</div>
css
#Container {
position: relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
/----------------------------------------/
#Header {
position: absolute;
height: 15%;
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
/*background-color: red;*/
}
I would avoid using position styling like that; it tends to interfere with the way block elements interact with each other. Based on the styles and markup provided, I don't see a reason why padding/margin would not be working; however your example doesn't actually show any padding/margin applied, so it's hard to say what might be going wrong.
I would alter your styling thusly:
#Container {
width: 96%;
margin-left: auto;
margin-right: auto;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
height: 15%; /* This should really be a static number, not a percentage*/
width: 100%;
border-bottom: 2px solid #e8e2e2;
margin-bottom: 20px; /* This will push elements below your header div down by 20 px*/
}
Try to add pading to header tag's self. Because it is relative to other containers.
#Container {
position:relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
position:relative;
height: 15%;
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
position:relative;
padding-top:20px;
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
/*background-color: red;*/
}
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
</div>
</div>
Firstly, please add #for Container as in #Container in css.
Below is the code where I have added margin bottom for h1. Please let me know if you still have any troubles.
<html>
<head>
<style type="text/css">
#Container {
position: relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
position: absolute;
height: 15%;
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
border:1px solid red;
margin-bottom:10px;
}
</style>
</head>
<body>
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
<p>some text here</p>
</div>
</div>
</body>
</html>
Hope this helps.
Thanks
Padding-bottom and margin-bottom does actually work, it's just that it's not visible because you're currently setting the height of #Header to 15% and then giving it that light grey bottom border. This is what gives the illusion that padding-bottom or margin-bottom doesn't work.
See working version here http://codepen.io/sajadtorkamani/pen/zxxzgo
HTML
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
</div>
</div>
CSS
Container {
position: relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
position: absolute;
/* height: 15%; */
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
padding-bottom: 20px;
/*background-color: red;*/
}
Just commenting out height: 15% for #Header solves the issue.
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;}
How can the parent div auto resize it's height based on the child's height?
div#main{
width: 970px;
height: 100px;
background: rgba(255,0,0,1);
border: 5px solid rgb(251,151,117);
margin: 20px 0px 20px 0px; /* Top Right Bottom Left*/
padding: 10px
}
div#left{width: 383px;
height: 100%;
margin-right: 5px;
background: rgb(0,0,255);
float:left
}
div#description{width: 100%;
height: 50%;
background: rgb(0,0,0)
}
div#following{width: 100%;
height: 50%;
background: rgb(0,255,0)
}
div#posts{width: 577px;
height: auto;
margin-left: 5px;
background: rgb(255,255,0);
float: right
}
<div id="main">
<div id="left" class="cell">
<div id="description" class="cell">
</div>
<div id="following" class="cell">
</div>
</div>
<div id="posts" class="cell">
there are some contents here (height is set to auto)
</div>
</div>
I made a very simple example for you to see how variable parent height works.
.parent
{
height: auto;
border: 1px dashed #f00;
padding: 5px;
}
.child
{
height: 100px;
border: 1px dashed #0f0;
}
<div class="parent">
<div class="child">
</div>
</div>
Follow what is there and you'll do fine.
After looking through your code it's a float problem, you have to add a new div to the bottom with clear: both; to clear the floats and make the #main div appear filled in.
Look at example here.
div#main{
width: 970px;
background: rgba(255,0,0,1);
border: 5px solid rgb(251,151,117);
margin: 20px 0px 20px 0px; /* Top Right Bottom Left*/
padding: 10px
}
Remove height attribute
CSS3
.container {
display: inline;
position: relative;
}
Should fix it. Use inline-block if you want it to be a block with inline.