Reputation: 11
I want to make footer to my website, and i want it to be fixed (always in the botton). It's working and looking fine, but when the content is full, it's not showing the margin-top that I gave it. Please help, i need a way to give fixed div - margin-top... Thanks.
Code:
<div style="width: 100%; height: 100px; margin-bottom: 50px; background: red;">
</div>
<div style="width: 100%; text-align: center;">
Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />Example of full div<br />
</div>
<div style="width: 100%; height: 50px; margin-top: 50px; background: blue; position: fixed; bottom: 0;">
</div>
Upvotes: 1
Views: 412
Reputation: 35
You should look into sticky footer, that will sort it out. And yeh you should really separate out your html from your css and you should use the footer tag if it's a footer. http://ryanfait.com/sticky-footer/
Upvotes: 1
Reputation: 82277
Place another fixed height div just below the blue one by using a z-index
. This will result in a white "margin" showing above the blue. The reason that the margin is not affecting the page is that position: fixed elements do not affect the page flow.
<div style="width: 100%; height: 100px; background: white; position: fixed; bottom: 0;z-index:1"></div>
<div style="width: 100%; height: 50px; background: blue; position: fixed; bottom: 0;z-index:2"></div>
Upvotes: 0