gpt4 book ai didi

css - 为什么 position fixed div 会跑到主容器外面?

转载 作者:太空宇宙 更新时间:2023-11-04 12:10:52 27 4
gpt4 key购买 nike

下面给出了固定的 div CSS:

.top-container {
position: fixed;
width: 100%;
z-index: 999;
}

当我缩小屏幕时,此 div 破坏了右侧的主容器,但左侧没问题。查看下面的屏幕截图以便更好地理解。

enter image description here

最佳答案

您必须了解position: fixed; 是如何工作的。它忽略任何周围的元素。

您可以找到详细信息here .

引用一段话:

A fixed position element is positioned relative to the viewport, or the browser window itself.

更新
您可以尝试使用与左侧元素宽度相同的 margin-left 和与 .top-container 右侧元素宽度相同的 margin-right 元素。这显然不是一个理想的解决方案,但可以解决您的问题。

关于css - 为什么 position fixed div 会跑到主容器外面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29053497/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com