CSS 位置绝对覆盖导航栏位置固定
我创建了两个图像的悬停效果。将鼠标悬停在 div“img3”中时,图像 1 会更改为图像 2。两个图像都在 div"img3" 中,image2 位置是绝对的。现在我的导航栏或标题(“标题”部分)位置已固定。因此,每当我将鼠标悬停在 image1 上时,image2 就会出现在导航栏的顶部,如下图 2 所示。 图片1 图片2
I have created hover effect of two images. image1 changes to image2 on hover in div"img3". Both images are in div"img3" and image2 position is absolute. Now my Navbar or header (section "header") position is fixed. So whenever I hover on image1 image2 comes on top of the Navbar as shown in the image2 below.
Image1
Image2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其添加到您的导航栏,
因为您添加的任何内容都不会超出导航栏。
Add this to your navbar
because of this whatever u add will not poke over navbar.
DarkForest的答案是正确的。
只是进一步解释一下 -
z-index
的属性定义网站元素的分层适用于
position:fixed
和position:absolute
。分层的默认行为是分层的,这意味着代码中较靠前的元素将最初覆盖第一个元素。除非您为这些元素中的一个或两个定义属性
z-index
。数字越大,显示越上层。
通常,您希望为固定导航栏分配尽可能高的 z-index ,因为您实际上并不希望在其上显示任何内容(除非它是其中的元素)
总而言之:
应该做把戏
The answer of DarkForest is correct.
Just to explain a bit further - the attribute of
z-index
whichdefines layering of site elements is applicable to both
position:fixed
andposition:absolute
. The default behavior of layering is hierarchical, which means, that the element which is further in the code will initialy overlay the first element.That is unless you define attribute
z-index
to one or both of these elements.the higher the number, the more upper layer of display.
Usually, you want to assign as high
z-index
as you can to the fixed navbar as you don't really want anything to display over it (unless it's an element inside of it)To summarize:
should do the trick