css - Bootstrap 粘性页脚代码在高度和填充之间发生冲突

标签 css twitter-bootstrap height

我正在尝试将 sticky-footer.html 示例添加到我的 Bootstrap 元素中。 但是,正文类中存在代码冲突,影响了我的布局。

在我的带有 bootstrap 响应式固定导航栏的页面代码中使用:

  body {
    padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}

在它使用的粘性页脚示例中:

  html,
  body {
    height: 100%;
    /* The html and body elements cannot have any padding or margin. */
  }

目前我的 css 中包含两个 body 标签。除桌面页面宽度版本外,一切正常,使用下面的当前 css 我得到一个具有额外深度的粘性页脚,并且该页面有一个垂直滚动条,即使它不需要一个?而这一切都与 body 标签冲突和额外的 60px 有关。

  /* Sticky footer styles
  -------------------------------------------------- */

  html,
  body {
    height: 100%;
    /* The html and body elements cannot have any padding or margin. */
  }

  /* Wrapper for page content to push down footer */
  #wrap {         
    min-height: 100%;
    height: auto !important;
    height: 100%;
    /* Negative indent footer by it's height */
    margin: 0 auto -190px;
  }

  /* Set the fixed height of the footer here */
  #push,
  #footer {
    margin-top:20px;
    height: 190px;      
  }
  #footer {       
background-image:url(assets/img/herringboneLight.jpg);   
  }

  /* Lastly, apply responsive CSS fixes as necessary */
  @media (max-width: 767px) {
    #footer {

    }
  }

 body {
    padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
 }

干杯 亚历克斯

最佳答案

我不知道您要支持哪些浏览器,但我相信 CSS3 解决方案 ( actually in IE8+) 会更改 body 上的 box-sizing >:

body {
    padding-top: 60px;
    -moz-box-sizing: padding-box; /* or border-box */
    -webkit-box-sizing: padding-box; /* or border-box */
    box-sizing: padding-box; /* or border-box */
}

这应该会导致 height: 100% 在总量中包含 60px。它在 Firefox 中工作,所以,this fiddle有滚动条,this one does not .

关于css - Bootstrap 粘性页脚代码在高度和填充之间发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14482376/

相关文章:

html - 未定义的 div 上的 CSS "page-break-after"

html - 带有内联元素的 CSS 省略号?

javascript - 检查一组复选框是否在 Bootstrap 中选中。

javascript - Jquery 回调未在 Bootstrap 选项卡中触发

html - div css高度调整

css - sRGB 和跨浏览器颜色差异

html - IE 8-10 表格中的图片太大

css - 仅更改 CSS3 和 Bootstrap 中导航属性的宽度属性

html - 滚动条及其内容隐藏在 div 之外

html - 文本行的确切高度(字体大小 + 行高)