【问题标题】:Adding margin to the top and not affecting the height of container在顶部添加边距并且不影响容器的高度
【发布时间】:2013-01-08 21:57:28
【问题描述】:

由于我的导航栏,我必须添加高度与导航栏高度相同的边距。但是,当我添加边距时,我得到一个滚动条,因为 body、html 和容器的高度设置为 100%。如何为导航栏添加边距,而不是获得不必要的滚动条?为什么margin-bottom: -42px; 不起作用?

body, html {
    height: 100%;
}

.navbar {
    z-index: 10;
}

.container-fluid {
    height: 100%;
    margin-top: 42px;
    // add margin from the nav bar
}

【问题讨论】:

  • 你能提供HTML吗?
  • 导航栏的位置现在是固定的

标签: css layout margin


【解决方案1】:
.container-fluid { overflow: hidden; }

这应该隐藏滚动条

【讨论】:

    【解决方案2】:

    试试这个.container-fluid { height: 100%; position:absolute; top:42px; } 绝对元素从 dom 中移除并准确放置在您指定的位置

    【讨论】:

    • 但是如果我将容器设置为绝对,流体属性是否仍然存在?
    猜你喜欢
    • 2015-09-12
    • 2015-03-05
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2010-11-17
    • 2011-04-27
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多