gpt4 book ai didi

CSS 相对定位防止点击链接

转载 作者:行者123 更新时间:2023-11-28 10:47:48 25 4
gpt4 key购买 nike

请在这里查看我的 jsfiddle - http://jsfiddle.net/ftuZ5/ .我知道为什么链接不起作用,因为我用来创建链接/菜单背景的相对定位覆盖了 a 元素,但我不知道如何解决这个问题(尝试过 relative 和 z-index在 li 和 a 元素上,加上添加和额外的 div 来跨越 a 元素,使用它来创建“按钮”样式的背景)但都无济于事。

li {
list-style: none;
}
.side-nav li {
padding-bottom: 3.125em;
width: 100%;
line-height: 1.25em;
text-align: center;
}
.side-nav a {
position: relative;
top: 1.75em;
z-index: -1;
display: block;
color: white;
text-decoration: none;
background: #c7cbaf;
-webkit-border-radius: 48px;
-moz-border-radius: 48px;
-ms-border-radius: 48px;
-o-border-radius: 48px;
border-radius: 48px;
padding-top: 1.375em;
padding-bottom: 0.75em;
text-transform: uppercase;
}
.responsive-side-nav {
background: transparent url(http://thewebbakery.co.uk/assets/graphics/responsive-icon-sml.png) no-repeat top center;
}

.interactive-side-nav {
background: transparent url(http://thewebbakery.co.uk/assets/graphics/interactive-icon-sml.png) no-repeat top center;
}

.ux-side-nav {
background: transparent url(http://thewebbakery.co.uk/assets/graphics/ux-icon-sml.png) no-repeat top center;
}

有人能帮忙吗?

最佳答案

这里有一个可能的解决方案:

JSFiddle

<nav class="side-nav" role=navigation>
<ul>
<li><a href="#"><div id="responsive-side-nav" class="side-nav-image"></div>Responsive Web Design</a></li>
<li><a href="#"><div id="interactive-side-nav" class="side-nav-image"></div>Interactive Web Design</a></li>
<li><a href="#"><div id="ux-side-nav" class="side-nav-image"></div>User Experience</a></li>
</ul>

通过将 anchor 标记包裹在图像的新 div 周围,整个内容变得可点击。

然后您可以根据需要放置图像(我为每个图像创建了一个通用类):

.side-nav-image
{
width: 100%;
height: 50px;
margin-top: -50px;
}

唯一的缺点是按钮的点击区域会增加以适应图像的大小。但是,如果您希望图像重叠,同时让整个图像都可以点击,我不确定是否可行。

关于CSS 相对定位防止点击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22894317/

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