CSS 问题 : Links on page becoming unclickable when other element is positioned "absolute"

标签 css height width position hyperlink

这是一个较长的故事,我想缩短它。一般来说,我正在玩一个网站菜单,该菜单应该在部分透明的背景 gif 图像下部分滑动,并且只有在鼠标悬停时才会完全显示出来。为此,我在背景图像和菜单上都使用了 z-index 参数。但是由于你不能在 body 背景图像上使用 z-index,我使用的是“常规”图像,我将其设置为 100% 宽度和高度 - 为了使 z-index 参数起作用,我需要也指定“位置”。似乎通过该组合,我基本上是在创建一个隐形防护罩,使所有链接都无法触及。我已将其简化为以下几行:

<style>
#style {
    position: absolute;
    width:100%;
    height:100%;
}
</style>

<div id="style"></div>
<a href="">test</a>

如果您尝试这样做,您将看到“测试”链接不可点击(跨浏览器)。

有人知道我该如何解决这个问题吗?谢谢!

最佳答案

<style>
#style {
    background-color:#ccc;
    position: absolute;
    width:100%;
    height:100%;
}
a {position:relative} /*won't change position of the link, but shows link above.*/
</style>



<div id="style"></div>
<a href="#">test</a>

关于CSS 问题 : Links on page becoming unclickable when other element is positioned "absolute",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7732674/

相关文章:

html - 如何将列表缩放到横向设备高度而不是列表内容高度

python - BeautifulSoup get_text() 函数包括 css

javascript - 暗模式在加载期间不起作用

ios - 在 heightForRowAtIndexPath 中推断行高

html - 没有宽度的中心 float 容器

javascript - 在从 css 加载其他图像之前加载 gif 图像

css - 如何在不对抗 CSS 的情况下实现这种布局

css - 根据内部图像调整元素高度

c++ - 是否可以检查将程序输出重定向到文件的控制台的宽度?

html - HTML/CSS 中带有居中元素的全宽标题