简体   繁体   English

页脚隐藏在简单的1列夹层CSS布局中的内容

[英]Footer is obscuring content in simple 1 column sandwiched css layout

I'm trying to get a seemingly simple mechanic to work with CSS only and I just keep running into walls. 我试图让一种看似简单的机制仅与CSS一起使用,而我一直碰壁。

The general layout is that I have a single column layout with a header and footer. 总体布局是我有一个带有页眉和页脚的单列布局。 I want the header and footer to stay "fixed" to the top and bottom of the viewport and I want the center section to adjust to fill the rest of the space with a vertical scroll bar if there is too much content. 我希望页眉和页脚保持“固定”在视口的顶部和底部,并且如果内容太多,我希望中间部分进行调整以用垂直滚动条填充其余空间。

I feel that I am very close, but the issue is that the central div extends to the bottom of the page behind the footer. 我觉得我已经很接近了,但是问题是中央div延伸到页脚后面页面的底部。 I'm guessing the problem is that I've specified the height of the central div to be 100%... I guess it boils down to not knowing how to subtract the fixed footer height and keep the central div responsive. 我猜问题是我将中央div的高度指定为100%...我想它归结为不知道如何减去固定的页脚高度并保持中央div响应。 Can this be be done with a purely CSS trick or do I need to use javascript to query the screen size and calculate the offset? 可以使用纯CSS技巧完成此操作,还是需要使用javascript查询屏幕尺寸并计算偏移量?

I've tried adding padding and margins to the bottom of the central div. 我试过在中央div的底部添加填充和边距。 It didn't work and even if it had, at best all the content would be visible but the scroll bar would still slip behind the footer. 它没有用,即使有,最多所有内容都可见,但滚动条仍会滑到页脚后面。 Which is not so clean. 哪个不是那么干净。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

HTML: HTML:

  <div class="container">
      <div class="header">Header</div>
      <div class="content">
         <h2>Layout</h2>
         LOTS of text
      </div>
      <div class="footer">
         <p>Footer</p>
      </div>
  </div>

CSS: CSS:

html,
body { height: 100%; 
overflow:hidden;}

.container {
    width: 70%;
    background-color: #FFF;
    height: 100%;
    position:relative;
    overflow:hidden;    
}

.header {
    background-color: #6F7D94;
    height: 60px;
}

.content {
    position:relative;
    padding: 10px 10px;
    overflow-y:scroll;
    overflow-x: hidden;
    height:100%;
    margin-bottom: 60px;
}

.footer {
    position: absolute;
    bottom: 0;
    height: 60px;
    width: 100%;
    padding: 0;
    background-color: #6F7D94;
}

Here is my Jfiddle 这是我的小提琴

You can use position:absolute; 您可以使用position:absolute; on your .content too like this : 在您的.content也是如此:

FIDDLE 小提琴

.content {
    position:absolute;
    top:60px; /* height of header */
    left:0;
    bottom:60px; /* height of footer */
    padding: 10px 10px;
    overflow-y:scroll;
    overflow-x: hidden;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM