防止一个元素覆盖另一个元素
我有一个固定的标题。当我滚动时,某些元素会覆盖标题。我该如何防止这种情况?
I have a fixed header. As I scroll, certain elements cover the header. How do I prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以立即想到两个解决方案。您可以为
#headercontainer
元素指定 z-index CSS property......或者您可以按照我认为应该完成的方式进行...
在第二个解决方案中,您不必担心哪个元素悬停在哪个其他元素上。
#contentcontainer
元素正确下推到#headercontainer
元素下方,以便它们没有重叠。There are two solutions I can think of quickly off the top of my head. You can either give the
#headercontainer
element a z-index CSS property...... or you can do it the way I think it should be done...
In the second solution, you don't have to worry about which element is hovering over which other element. The
#contentcontainer
element is properly pushed down under the#headercontainer
element so that they have no overlap.您应该为 div 设置 z-index:
添加上述行应该使标头优先于内容容器。
You should set the z-index for the divs:
Adding the above lines should give your header priority over the content container.
为
#headercontainer
提供更高的 z-index:Give the
#headercontainer
a higher z-index: