简体   繁体   中英

Anchor tags href not working

Edit: closing anchor fixed. This issue exists when testing on the following browsers:

  • Google Chrome
  • Firefox 3.5
  • Safari

Works with no problems on IE 8

I'v a really weird problem here. In short, take a look at the following 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{
    border: 1px solid #c8c8c8;
    display:block;
    background:#fff; 
    height: 100px
}

and the img class:

.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).

Any ideas?

Some browsers have issues with anchors that are display: inline (the default) containing elements that are display: block .

Add display: block to the ruleset with the .img selector.

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.

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM