在 CSS 中保持页脚可见且高度为 100%

发布于 2024-09-02 01:10:52 字数 905 浏览 4 评论 0 原文

我正在尝试创建一个非常简单的页面,其中包含容器、页眉、左栏和页脚:

<containter>
<header />
<content />
<leftBar />
<footer />
</containter>

我想使用 100% 的高度,就像我可以使用宽度一样,但我只是不t让它工作。目前我正在使用min-height,但是我如何使用height:100%`?我喜欢的是页脚始终可见,并且您可以滚动内容。

当前 CSS

body
{
    font-family: Verdana;
    font-size: 0.8em;
    background-color:#f1f1f1;
}

#container {
   border:solid 2px Black;
   position:absolute;
   left:10%;
   width:80%;
   margin:auto;
}

#header {
  height:20px;
  background: #DDDDDD;
}

#leftBar {
  width: 20%; 
  background: #669966; 
  min-height:600px;
  postion:absolute;
  top:20px;
  bottom:20px;
}

#content {
  float:right;
  background-color: #cdcde6;
  position:absolute;
  left:20%;
  right:0px;
  bottom:20px;
  top:20px;
  padding:5px;
}

#footer {
 position:absolute;
 height:20px;
}

I'm trying to create a very simple page that contains a container, a header, a left column and a footer:

<containter>
<header />
<content />
<leftBar />
<footer />
</containter>

I want to use the 100% of the height, as I can do with the width, but I simply dont get it work.At his moment I'm using min-height, but how could I use the height:100%` ? What I like is that the footer is always visible, and you scroll the content.

Current CSS

body
{
    font-family: Verdana;
    font-size: 0.8em;
    background-color:#f1f1f1;
}

#container {
   border:solid 2px Black;
   position:absolute;
   left:10%;
   width:80%;
   margin:auto;
}

#header {
  height:20px;
  background: #DDDDDD;
}

#leftBar {
  width: 20%; 
  background: #669966; 
  min-height:600px;
  postion:absolute;
  top:20px;
  bottom:20px;
}

#content {
  float:right;
  background-color: #cdcde6;
  position:absolute;
  left:20%;
  right:0px;
  bottom:20px;
  top:20px;
  padding:5px;
}

#footer {
 position:absolute;
 height:20px;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

逆流 2024-09-09 01:10:52
/**
 * The following allows the usage of height=100% in body tag.
 * Creds to: http://apptools.com/examples/tableheight.php
 */
html,body
{
    margin    : 0;
    padding    : 0;
    height    : 100%;
    border    : none;
}

您需要使其 html 和 body 占据 100% 的浏览器视口。

/**
 * The following allows the usage of height=100% in body tag.
 * Creds to: http://apptools.com/examples/tableheight.php
 */
html,body
{
    margin    : 0;
    padding    : 0;
    height    : 100%;
    border    : none;
}

You need to make it so html and body take 100% of the browser viewport.

赠我空喜 2024-09-09 01:10:52

我不确定这是否正是您所要求的,但在 css 布局方面它是一个很好的资源 http://matthewjamestaylor.com/blog/perfect-multi-column-liquid-layouts。它还有一篇文章解释如何将其添加到容器中: http://matthewjamestaylor.com/blog/how-to-convert-a-liquid-layout-to-fixed-width

I´m not sure if this is exactly what you are asking for, but it is a good resource when it comes to css layout http://matthewjamestaylor.com/blog/perfect-multi-column-liquid-layouts. It also has an article explaining how to add it into a container: http://matthewjamestaylor.com/blog/how-to-convert-a-liquid-layout-to-fixed-width

那请放手 2024-09-09 01:10:52
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
  html, body { margin: 0 auto; height: 100%; }
  #container { height: 100%; width: 80%; background: #e0e0e0; margin: 0 auto;}
</style>
</head>
<body>
  <div id="container">
  </div>
</body>
</html>

http://jsbin.com/uyezu

技巧是将 html,body 扩展到 100%

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
  html, body { margin: 0 auto; height: 100%; }
  #container { height: 100%; width: 80%; background: #e0e0e0; margin: 0 auto;}
</style>
</head>
<body>
  <div id="container">
  </div>
</body>
</html>

http://jsbin.com/uyezu

Trick is to expand html,body to 100%

ゝ杯具 2024-09-09 01:10:52

实际上,我今晚自己刚刚解决了类似的问题,以下链接提供了完美的解决方案:

http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

希望有帮助。

I've actually just fixed a similar problem myself this evening, and the following link provided the perfect solution:

http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

Hope it helps.

熊抱啵儿 2024-09-09 01:10:52

我已经使用它很多年了,仍然效果很好:

footerStickAlt:一种更强大的定位页脚的方法
http://www.themaninblue.com/writing/perspective/2005/08 /29/

I've been using this for years, still works great:

footerStickAlt: A more robust method of positioning a footer
http://www.themaninblue.com/writing/perspective/2005/08/29/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文