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

标签 html css height

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

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

我想使用 100% 的高度,就像我可以使用宽度一样,但我只是没有让它工作。此时我正在使用 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;
}

最佳答案

/**
 * 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 占据浏览器视口(viewport)的 100%。

关于html - 在 CSS 中保持页脚可见且高度为 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2878598/

相关文章:

jquery - css 类的优先级

html - 为什么我的最小高度为 : 100% looks weird on mobile?

html - 2 个人造列,中间是液体,html/body 上没有 bg 的粘性页脚?

css - 如何使不透明度仅适用于 div 类中的背景

css - 如何使最后一个 div 拉伸(stretch)以填满屏幕?

android - 按钮的高度自动改变android

html - nav 包含在 header 中 vs 不包含在 header 中?

html - 使 CSS flexbox 成为其内部元素的宽度

css - 如何根据父div中子div的数量设置div的高度

html - 部分悬停由 CSS3 激活和不激活