我正在摆弄我正在开发的一个网站,试图修复一些奇怪的 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.
发布评论
评论(3)
如果没有该网站的链接,很难准确判断出了什么问题。但无论如何,解决方案可能是使用
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 ofa
. For examplez-index:100
. Keep in mind thatz-index
works only with positioned elements, so you can useposition:relative
.Demo based on your example: http://jsfiddle.net/gBchZ/3/
这是因为
.content
div
覆盖了右框(在您的演示中)。如果您向这些 div 添加margin-right
,则a
变为“可访问:”JS Fiddle demo
您还可以使用
position:absolute;
使a
元素在中显示“更高” z-index
,尽管这变得相当复杂:JS Fiddle demo
This is because the
.content
div
s are covering the right-box (in your demo). If you add amargin-right
to those divs thea
becomes 'reachable:'JS Fiddle demo
You could also use
position: absolute;
to make thea
element appear 'higher' in thez-index
, though this becomes rather complex:JS Fiddle demo
@David 是正确的,
.content
项上的 >position:relative 为它们提供了 z 索引,这意味着它们位于您浮动到右侧的链接的“顶部”。我认为更好的解决方案是将
position:relative;
添加到您向右浮动的链接,并为其指定高于.content
的 z-index:请参阅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
:See http://jsfiddle.net/gBchZ/6/