【问题标题】:Strange behavior with position fixed [duplicate]位置固定的奇怪行为[重复]
【发布时间】:2019-04-06 08:40:40
【问题描述】:

这是一个代码笔,我的意思是: https://codepen.io/anon/pen/MReEQw,代码如下:

<div id="fixed">
</div>

<div id="content">
</div>


#fixed {
    height: 50px;
    width: 100%;
    background-color: green;
    position: fixed;
}

#content {
    height: 2000px;
    background: grey;
    margin-top: 50px;
}

这是margin-collapse吗?为什么我不能设置一个固定的div,然后在它下面设置一个不重叠的div?

【问题讨论】:

  • 你希望你的 div 固定在页面顶部还是你想要边距?

标签: html css


【解决方案1】:

如果您希望 div #fixed 位于顶部,则添加此属性

#fixed {
    height: 50px;
    width: 100%;
    background-color: green;
    position: fixed;
    top: 0;
}

【讨论】:

    猜你喜欢
    • 2012-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2013-07-01
    • 2015-07-19
    • 1970-01-01
    相关资源
    最近更新 更多