仅在 IE7 中,图像在锚点内不可单击
Html 结构
<a>
<span> <!-- Span has width & height -->
<img>
</span>
<span> Some text <span>
</a>
锚点仅在 IE7 中不可单击,我知道问题的发生是因为 hasLayout,如果我们删除 height &跨度的宽度,它会工作得很好。
但我需要让它在不删除高度和高度的情况下工作。宽度。
编辑:您可以在这里摆弄一个示例:http://jsfiddle.net/rxcAb
Html Structure
<a>
<span> <!-- Span has width & height -->
<img>
</span>
<span> Some text <span>
</a>
Anchor is not clickable only in IE7, I know the issue happens because of hasLayout, if we remove height & width of the span, it will work fine.
But I need to make it work with out removing height & width.
EDIT: You can fiddle with an example here: http://jsfiddle.net/rxcAb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
仅 CSS 解决方案
Tomas-我将您的小提琴修改为一个工作示例。我将您的代码更改为在
a
标记内使用span
,因为在内联元素(a
标记)。提供a
标签布局(我使用inline-block
),然后在该span
上设置position:relative
使用z-index: -1
将span
推到a
标记“下方”,并使 IE7 识别a
> 再次标记为活动状态。下面是我的小提琴中使用的修改后的代码。您可能想要设置一个比我的ie7AFix
更通用的类名(您可能还希望仅针对 IE7 所需的 CSS 属性)。我假设您正在通过图像改变宽度
和高度
,因此您将它们作为内联样式。HTML
CSS
更新的 Fiddle<如果不想只针对 IE7,则添加
line-height
来实现“跨浏览器”。我将width
和height
保留在上面的span
html 中,只是因为原始问题(由 gviswanathan 和 Tomas 提出)要求这样做。如果由于某种原因您不需要在span
上设置尺寸,而只是尝试在图像上设置双边框,则 下面评论中给出的thirtydot的答案要简单得多。CSS Only Solution
Tomas-I modified your fiddle into a working example. I changed your code to use a
span
inside thea
tag because it is invalid to have a standard block level element (adiv
) in an inline element (ana
tag). Giving thea
tag layout (I usedinline-block
) and then setting aposition:relative
on thatspan
with az-index: -1
pushes thespan
"below" thea
tag and makes IE7 recognize thea
tag as active again. Below is the modified code used in my fiddle. You might want to set up a more generic class name than myie7AFix
(you probably will also want to just target IE7 for those CSS properties that are necessary for it only). I assume you are varying thewidth
andheight
by images, and hence why you have those as inline styling.HTML
CSS
Updated Fiddle with
line-height
added to make "cross browser" if one does not want to target IE7 only. I kept thewidth
andheight
in thespan
html above, only because the original question (by both gviswanathan and Tomas) requested it. If you don't need to set the dimensions on thespan
for some reason, but are simply trying to do a double border on the image, then thirtydot's answer given in the comment's below is much simpler.使用 jQuery,以下内容将强制所有链接工作,并具有“指针”光标:
我已经在兼容视图模式下测试了模拟 IE7 和 IE8,但不能保证它本身适用于 IE7。
您可能希望更有选择性地应用它 - 我怀疑这可能会降低旧版浏览器的性能 - 在这种情况下应用一个类(例如
) 到所有以这种方式损坏的链接,只需将
$('a')
更改为$('.myClass')
With jQuery, the following will force all links to work, and have the 'pointer' cursor:
I've tested this simulating IE7 with IE8 in compatibility view mode, but can't guarantee it will for IE7 on its own.
You may want to apply this more selectively -- I suspect that, as is, this might slow down older browser performance -- in which case apply a class (like
<a href='myClass'>
) to all links that are broken this way, and just change$('a')
to$('.myClass')
您尝试过使用 HTML5 shim 吗?它对解决由 hasLayout 引起的问题有很大帮助。
Have you tried using the HTML5 shim? It helps a lot with issues that are caused by hasLayout.
只需从 IMG 中取出 SPAN 即可。 IMG 元素可以像任何其他元素一样使用类进行样式设置,因此您不需要在它周围使用跨度。
Just take out the SPAN from the IMG. The IMG element can be styled with a class just like any other element, therefore you don't need a span around it.
将以下 CSS 规则赋予 a 元素:
give the following CSS rules to the a element:
啊 另一个 hasLayout 怪癖
在 IE7 中不可能实现并仍然保留跨度的宽度,如果你可以展示你想要在 JS 小提琴中实现的目标,也许我们可以提供帮助,找到一种解决方法,例如,这只是一个猜测,将宽度放在
anchor
上并进行一些填充将有助于创建一个完全可点击的区域,并且仍然允许限制“标题”跨度(如果这就是您所追求的)。示例解决方法不是修复
CSS:
HTML:
以上只是一个想法,如果这不是您想要的,那么请提供一个示例jsfiddle。网
Ah another hasLayout quirk
it's not possible to achieve in IE7 and still retain the width of the span, if you could show what you're trying to achieve in a JS fiddle perhaps we could help, find a way around it e.g. and this is only a guess, putting the width on the
anchor
with some padding would help create a completely clickable area and still allow a "caption" span to be restrained if that's what you're after..Example workaround not a fix
CSS:
HTML:
The above is only a thought, and if it's not what you're after, then please provide a sample jsfiddle.net
可能是问题是因为您没有在
标签中定义
href="#"
所以,把href="#"
在您的标签内。像这样写:
May be it's a problem is that because you didn't define
href="#"
inside your<a>
TAG So, puthref="#"
inside your<a>
TAG. Write like this:只需将锚标记包裹在 Div 或 Span 内即可。它在 IE7 中工作。
这个方法错了..?
Just wrap anchor tag inside Div or Span. Its working in IE7.
This way is wrong..?
从你的帖子中,我认为你想要一个带有跨度信息文本的可点击图像!我希望这对你有帮助;)
http://jsfiddle.net/ajinkyax/v5KH5/3/
CSS:
From your post I think u wanted a clickable image with span info text !! I hope this will help u ;)
http://jsfiddle.net/ajinkyax/v5KH5/3/
CSS:
请参阅小提琴代码和演示
小提琴: http://jsfiddle.net/rxcAb/29/
演示: http://jsfiddle.net/rxcAb/29/embedded/result/
完美工作在 IE7、IE8、FF、Chrome、Safari 中。
代码没有变化:见下文
See fiddle for code and demo
Fiddle: http://jsfiddle.net/rxcAb/29/
Demo: http://jsfiddle.net/rxcAb/29/embedded/result/
Perfectly working in IE7, IE8, FF, Chrome, Safari.
No changes in code: See below
一个简单的方法是:
An easy way to do this is:
如果您有类似的内容:
只需向锚添加一个样式属性,如下所示:
这将使 div 及其内部的所有内容在 IE7+ 和 firefox & 中可单击。铬合金。
If you have something like:
Simply add a style property to the anchor like this:
This will make the div and everything inside of it clickable in IE7+ and firefox & chrome.