html - 我怎样才能有一个固定的顶部栏,100% 的内容

标签 html css

我现在有这样的东西...我希望内容占页面的 100% - 距顶部栏 100 像素。但它不起作用。

<style>

#content{
    display: block;
    height: 100%-100px; <!-- I need something to fix this, because it doesnt work -->
}

#topbar{
    height: 100px;
    display: block;
}

</style>

最佳答案

每个人都一直在建议 margin-top,但是在 100% 高度下效果不佳。

如果你想要一个真正的固定标题,试试这样的东西

#content {
  height: 100%;
  padding-top: 100px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

#topbar {
  height: 100px;
  position: fixed;
}

更新:Here is a link to a CodePen example

这是示例中的重要代码:

html, body {
  height: 100%;
}

#topbar {
  height: 100px;
  width: 100%;
  position: fixed;
}

#content {
  height: 100%;
  padding-top: 100px;
  box-sizing: border-box;
}

关于html - 我怎样才能有一个固定的顶部栏,100% 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20549696/

相关文章:

css - 缩放 HTML5 视频并打破纵横比以填充整个站点

css - HTML CSS 试图使固定的 sidenavbar 响应

html - rails : Redirect form_tag with radio button to 'show' page

html - 数据列表在 Safari 中不工作

html - 与负边距和 float 重叠

css - 在一些文本后添加行

javascript - 为什么 requestAnimationFrame() 嵌套在这个 if 语句中时不起作用?

css - Sass - 包含大量 css 文件的复杂文件夹结构

html - 使用具有可变高度的 Bootstrap div 创建网格

html - 使登录链接与其他链接对齐