Reputation: 113
I want to divide my page in 3 sections (header, content, footer). The problem is that the footer is not at the bottom as it should be, it is at the middle of the page. What am I doing wrong?
#page{
margin: 0 auto;
}
html{ height:100%;
margin:0;
padding:0;}
body{
height:100%;
margin:0;
padding:0;
background:#FFF;
font-family: verdana;
background-color: white;
}
#header{
top: 0px;
width: 100%;
height:2.5em;
border-bottom: 1px solid rgba(168, 164, 164, 1);
background-color: #FAF0E6;
}
#content{ a
width: 100%;
height:100%;
text-align: center;
}
#formulario{
width:48em;
margin-top:2em ;
margin-right: auto;
margin-left:auto;
}
#footer{
margin-top:2em;
margin-bottom: 0px;
bottom:0em;
font-size: 1em;
font-family: "lucida grande";
text-align: center;
width: 100%;
height:1.5em;
background-color: #D0F5A9;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="page">
<div id="header">
hi
</div>
<div id="content">
<div id="formulario" >hi
</div>
</div>
<div id="footer">
hi</div>
</div>
</body>`enter code here`
</html>`enter code here`
Upvotes: 1
Views: 440
Reputation: 22992
I would recommend you to use class
instead of id
for the best practice because id
can only be used once but you could use class
multiple times. You could do it like this:
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
font-family: verdana;
background-color: white;
background: #FFF;
height: 100%;
width: 100%;
margin: 0;
}
.header {
background-color: #FAF0E6;
position: relative;
width: 100%;
height: 2.5em;
border-bottom: 1px solid rgba(168, 164, 164, 1);
}
.content {
position: relative;
width: 100%;
min-height: 100%;
text-align: center;
margin-top: -2.5em;
margin-bottom: -1.5em;
padding-top: 2.5em;
padding-bottom: 1.5em;
}
.formulario {
width: 48em;
margin-top: 2em;
margin-right: auto;
margin-left: auto;
}
.footer {
background-color: #D0F5A9;
position: relative;
width: 100%;
height: 1.5em;
font-family:"lucida grande";
font-size: 1em;
text-align: center;
}
<div class="header">hi</div>
<div class="content">
<div class="formulario">HI!</div>
</div>
<div class="footer">hi</div>
Upvotes: 1
Reputation: 810
You need add position
attribute inside footer id and set it to absolute
. You didn't mention the position of the footer that's why it was in the middle.
like that
#footer{
margin-top:2em;
margin-bottom: 0px;
bottom:0em;
position:absolute;
font-size: 1em;
font-family: "lucida grande";
text-align: center;
width: 100%;
height:1.5em;
background-color: #D0F5A9;
}
#page{
margin: 0 auto;
}
html{ height:100%;
margin:0;
padding:0;}
body{
height:100%;
margin:0;
padding:0;
background:#FFF;
font-family: verdana;
background-color: white;
}
#header{
top: 0px;
width: 100%;
height:2.5em;
border-bottom: 1px solid rgba(168, 164, 164, 1);
background-color: #FAF0E6;
}
#content{ a
width: 100%;
height:100%;
text-align: center;
}
#formulario{
width:48em;
margin-top:2em ;
margin-right: auto;
margin-left:auto;
}
#footer{
margin-top:2em;
margin-bottom: 0px;
bottom:0em;
font-size: 1em;
font-family: "lucida grande";
text-align: center;
width: 100%;
height:1.5em;
position:absolute;
background-color: #D0F5A9;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="page">
<div id="header">
hi
</div>
<div id="content">
A
A
A
A
A
v
A
<div id="formulario" >hi
</div>
</div>
<div id="footer">
This is footer</div>
</div>
</body>
</html>
Upvotes: 0
Reputation: 1885
There are two things need to be noticed:
The footer
DIV shouldn't is a child node of content
DIV. Because the footer
is sibling to the header
.
After change the footer of DOM position.Both of
position:fixed;bottom:0;
and position: absolute; bottom:0;
is fit for your situation.
Upvotes: 0
Reputation: 8366
#page{
margin: 0 auto;
}
html{ height:100%;
margin:0;
padding:0;}
body{
height:100%;
margin:0;
padding:0;
background:#FFF;
font-family: verdana;
background-color: white;
}
#header{
top: 0px;
width: 100%;
height:2.5em;
border-bottom: 1px solid rgba(168, 164, 164, 1);
background-color: #FAF0E6;
}
#content{ a
width: 100%;
height:100%;
text-align: center;
}
#formulario{
width:48em;
margin-top:2em ;
margin-right: auto;
margin-left:auto;
}
#footer{
margin-top:2em;
margin-bottom: 0px;
bottom:0em;
position:absolute;
font-size: 1em;
font-family: "lucida grande";
text-align: center;
width: 100%;
height:1.5em;
background-color: #D0F5A9;
}
<body>
<div id="page">
<div id="header">
hi
</div>
<div id="content">
<div id="formulario" >hi
</div>
<div id="footer">
hi</div>
</div>
</div>
</body>
position:absolute;
for your footer
Upvotes: 0