Header and footer with fixed position while content is scrollable?

后端 未结 3 1360
无人及你
无人及你 2020-12-31 10:05

I\'m trying to make a website where header and footer have fixed position while content scrolls in the middle.

相关标签:
3条回答
  • 2020-12-31 10:39
    1. remove the position styles on the header and footer
    2. set a height on the content
    3. add a style overflow-y:auto to the content

    If you want the content height to match the browser window (less the header and footer), use javascript to set it (and adjust on window resize events)

    0 讨论(0)
  • 2020-12-31 10:48

    The easiest fix for this is to add padding equivalent to the height of your static header and footer:

    #content {
        width: 80%;
        margin: 0 auto;
        padding: 60px 0;
    }
    

    JSfiddle

    0 讨论(0)
  • 2020-12-31 10:56

    http://jsfiddle.net/yASFU/

    <header>header</header>
    <section>
        <div class="push">push</div>
    </section>
    <footer>footer</footer>
    
    html, body {height:100%; margin:0; overflow:hidden;}
    header, footer {display:block; background-color:black; height:10%;}
    section {height:80%; background-color:lightblue; display:block; overflow:auto;}
    section .push {height:4000px;}
    
    0 讨论(0)
提交回复
热议问题