Reputation: 838
Within my body
tag I have a header
and div#content
element. My aim was to create a fixed header and then push the content
of the content
element out from under it using a margin-top
attribute. However when I did this the header
also moved down as though it were joined to the content
. I fixed this by adding a position: absolute
to the content
. The trouble is I cant explain to myself why it worked. It just did. I am using Firefox on Ubuntu.
This is the header
css:
header {
position: fixed;
top: 0px,
left: 0px;
margin: 0px;
background-color: #3F51B5;
font-family: sans-serif;
color: #FFFFFF;
width: 100%;
z-index: 1;
}
This is the content
css:
#content {
position: absolute;
margin-top: 100px;
}
Here is the codepen.
Please educate me someone :)
Upvotes: 1
Views: 48
Reputation: 26
You used a comma instead of a semicolon here
Please replace the comma with smemicolon than you dont need position: absolute .
Upvotes: 1
Reputation: 5534
Several observations:
position: absolute;
didn't really fix it. Check out this codepen for a demonstration. Notice the fair amount of content I added after your div
s and how they don't display correctly? This is because:,
instead of ;
. You didn't close the top: ;
attribute so your browser tried to fix it by using the #content
margin-top
.Upvotes: 1
Reputation: 1183
Bad syntax-- used a ,
instead of ;
on line 3
header {
position: fixed;
top: 0px,
left: 0px;
so the attributes top
and left
are wrecked.
Upvotes: 1