height
属性设置为两个不同的值:92%和8%(使用vh
也不起作用)。无论我在CSS中指定的height
是什么(不同的单位等),我的页脚div
都无法固定。只要我删除height
属性,它就能按预期工作。这是我页面在删除
height
属性之前的截图:
如你所见,它并不会粘住。
在删除了height
属性值之后,它确实粘住了。
以下是相关代码:
html,
body {
height: 100%;
margin: 0;
}
#main {
height: 92%;
}
#landing {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
text-align: center;
}
#landingContent {
width: 20vw;
}
#footerNav {
height: 8%;
display: flex;
align-items: center;
position: -webkit-sticky;
position: sticky;
top: 0px;
}
<div id="main">
<div id="landing">
<div id="landingContent">
<h1 class="logo">Logo</h1>
<p id="landingParagraph">Lorem ipsum, paragraph content, etc etc.</p>
<button>Button</button>
</div>
</div>
</div>
<div id="footerNav">
<div id="footerNavContent">
<h1 class="logo">Logo</h1>
</div>
</div>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
overflow
属性可能会有问题,尽管它目前不存在,我也没有听说过其他人对height
有任何问题。当然,我可能是错的。我已经在以下浏览器上进行了测试:
- Firefox 61(夜间版)
- Safari 53(技术预览版)
- Chrome 65
#main
中删除height
属性可以使#footerNav
保持粘性。