0
A while ago I was looking for how to put header and footer fixed at the top and bottom of the page respectively, adjusting to the content that would be between the two, and I got with the following code:
CSS:
#wrapper {
min-height: 100%;
position: relative;
}
#container {
background: red;
padding-bottom: 80px;
overflow: hidden;
}
#content {
background: blue;
width: 1000px;
margin: 0 auto;
}
header {
height: 52px;
background: black;
}
header div {
width: 1000px;
background: red;
height: 52px;
margin: 0 auto;
}
HTML
<div id="wrapper">
<div id="container">
<header>
<div></div>
</header>
<div id="content"></div><!--content-->
</div><!--container-->
</div><!--wrapper-->
I would like to know how, using this code, I can fix the header at the top by scrolling the page, but keep the structure of the content and of footer.
What it means to "maintain content and footer structure"?
– Bacco
The content would be what is between the header and the footer, which will adjust regardless of the size, and even then the footer would be in the fixed footer, and the header at the top ....
– Thiago
I guess that’s what @Daniel answered then. The only thing you have to add is a padding in the content, above and below the same size as the footer and header, so the beginning and end of the content will not be covered up.
– Bacco
I just saw the demo on Jsfiddle, but the footer is also fixed, it was just the header, for example, as it is on Facebook and Youtube, the header with the search bar is fixed and accompanies the scrolling of the site, but not the footer, the footer Fican the end of the page, understood?
– Thiago
These things you have to always put in the body of the question, because I also only understood by the comments here below. Look in the next ones to describe the problem better, then we can help you better and at the same time whoever answers does not waste time with something that is not useful to you. But the solution is simple, he put one entry in the CSS for the header and another for the footer. Just don’t use the footer. If you want the footer to be at the bottom of the page when it is smaller than the screen, just a min-height:100% and body and html height with 100% as well.
– Bacco
Yes, I only used the header snippet, and it worked , it is fixed and following the scrolling of the page, but it is "covering" the padding that I gave in the text that was inside the "content", how can I solve this?
– Thiago
Increasing the top padding of the content pro header size, plus the space you want.
– Bacco
Thanks, I did that, only I thought it was gambiara haha, but thanks
– Thiago