Html 锚标签 href 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1125188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Anchor tags href not working
提问by Galilyou
Edit:closing anchor fixed. This issue exists when testing on the following browsers:
编辑:关闭锚定。在以下浏览器上测试时存在此问题:
- Google Chrome
- Firefox 3.5
- Safari
- 谷歌浏览器
- 火狐 3.5
- 苹果浏览器
Works with no problems on IE 8
在 IE 8 上没有问题
I'v a really weird problem here. In short, take a look at the following html:
我这里有一个非常奇怪的问题。总之,看看下面的html:
<a href="login_page.html" class="img">
<span class="img_holder">
<img src="images/columnists/mike_zeisberger248.jpg" onerror="this.src='default.jpg'"/>
</span>
<span class="btn">track him</span></a>
Here's the img_holder
css class:
这是img_holder
css类:
.img_holder{
border: 1px solid #c8c8c8;
display:block;
background:#fff;
height: 100px
}
and the img
class:
和img
班级:
.img{
_margin:0 12px 12px 0;
}
Now, the problem is that clicking the image nested inside the anchor tag doesn't take you to its href link (thought, the href link shows in the status bar when hovering over the image, and opens perfectly fine when opening in new tab).
现在,问题是单击嵌套在锚标记内的图像不会将您带到其 href 链接(认为,将鼠标悬停在图像上时,href 链接会显示在状态栏中,并且在新选项卡中打开时打开得很好) .
Any ideas?
有任何想法吗?
回答by Quentin
Some browsers have issues with anchors that are display: inline
(the default) containing elements that are display: block
.
某些浏览器存在锚点问题,这些锚点display: inline
(默认)包含display: block
.
Add display: block
to the ruleset with the .img
selector.
display: block
使用.img
选择器添加到规则集。
Also see http://validator.w3.org/— it makes a good first pass to find the low hanging fruit of QA issues. Your sample code seems to have some errors that it would pick up.
另请参阅http://validator.w3.org/——这是找到 QA 问题的低悬果的良好第一步。您的示例代码似乎有一些错误,它会发现。
回答by Williham Totland
Well, there area few obvious problems that spring out; one is the / before your onerror
, and the second is that the <a>
in question doesn't seem to be closed.
嗯,出现了一些明显的问题;一个是你之前的 / onerror
,第二个是有<a>
问题的似乎没有关闭。
Apart from that, there doesn't seem to be any obvious reasons why it wouldn't work; perhaps a more complete post of source code is in order?
除此之外,似乎没有任何明显的原因使它不起作用;也许更完整的源代码帖子是有序的?