位置:相对导致锚点不可点击

发布于 2024-10-20 18:32:47 字数 386 浏览 2 评论 0 原文

我正在摆弄我正在开发的一个网站,试图修复一些奇怪的 IE7 错误,因为这是一个内部项目,而 IE7 是标准浏览器。我最终添加了“position:relative”来纠正几个特定于 IE 的布局问题,但我似乎在 FF/Chrome 中让事情变得更糟(我认为自己更像是一名系统程序员,但我目前的职责涉及更多的网络不幸的是,焦点)。

具体问题是“position:relative”元素最终使我的一些链接浮动到右侧,无法单击。我创建了一个简单的测试页面,我希望它能比我用文字更好地解释这一点: http://jsfiddle.net/gBchZ/

我最终会解决这个混乱,但我希望有人能解释我的链接隐藏在位置后面的原因:相对元素。

I was fiddling around with a web site I am developing, attempting to fix some odd IE7 bugs, since this is an internal project and IE7 is the standard browser. I ended up adding "position: relative" to correct a couple IE-specific layout problems, but I seem to have made things worse in FF/Chrome (I consider myself more of a systems programmer, but my current responsibilities involve more of a web focus unfortunately).

The specific problem is that the "position: relative" elements ended up making some of my links, which were floated to the right, unclickable. I've created a simple test page that I hope will explain this better than I can with words: http://jsfiddle.net/gBchZ/.

I will sort through this mess eventually, but I was hoping that someone could explain the reason behind my links getting hidden behind the position: relative elements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瀞厅☆埖开 2024-10-27 18:32:48

如果没有该网站的链接,很难准确判断出了什么问题。但无论如何,解决方案可能是使用 z-index 作为 a 的父级。例如z-index:100。请记住,z-index 仅适用于定位元素,因此您可以使用 position:relative

基于您的示例的演示: http://jsfiddle.net/gBchZ/3/

Without having the link of the site is difficult to tell exactly what is wrong. But in any case, a solution could be to use z-index for the parent of a. For example z-index:100. Keep in mind that z-index works only with positioned elements, so you can use position:relative.

Demo based on your example: http://jsfiddle.net/gBchZ/3/

慢慢从新开始 2024-10-27 18:32:48

这是因为 .content div 覆盖了右框(在您的演示中)。如果您向这些 div 添加 margin-right ,则 a 变为“可访问:”

.content
{
    position: relative;
    margin-right: 20%;
}

JS Fiddle demo

您还可以使用 position:absolute; 使 a 元素在 中显示“更高” z-index,尽管这变得相当复杂:

#rightBox
{
    background-color: green;
    width: 25px;
    height: 25px;
    position: absolute;
    right: 0;
    top: 50%;
    margin: -20px .5em .5em .5em;
    padding: .5em;
}

JS Fiddle demo

This is because the .content divs are covering the right-box (in your demo). If you add a margin-right to those divs the a becomes 'reachable:'

.content
{
    position: relative;
    margin-right: 20%;
}

JS Fiddle demo

You could also use position: absolute; to make the a element appear 'higher' in the z-index, though this becomes rather complex:

#rightBox
{
    background-color: green;
    width: 25px;
    height: 25px;
    position: absolute;
    right: 0;
    top: 50%;
    margin: -20px .5em .5em .5em;
    padding: .5em;
}

JS Fiddle demo

攒眉千度 2024-10-27 18:32:48

@David 是正确的,.content 项上的 >position:relative 为它们提供了 z 索引,这意味着它们位于您浮动到右侧的链接的“顶部”。

我认为更好的解决方案是将 position:relative; 添加到您向右浮动的链接,并为其指定高于 .content 的 z-index:

#rightBox
{
    ...
    position: relative;
    z-index: 2;
}

.content
{
    position: relative;
    z-index: 1;
}

请参阅http://jsfiddle.net/gBchZ/6/

@David’s correct in that the position: relative on the .content items is giving them a z-index, meaning they’re “on top” of the link you’ve floated to the right.

I think a better solution though is to add position: relative; to the link you’ve floated right as well, and give it a z-index higher than .content:

#rightBox
{
    ...
    position: relative;
    z-index: 2;
}

.content
{
    position: relative;
    z-index: 1;
}

See http://jsfiddle.net/gBchZ/6/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文