Remove line under image in link

前端 未结 8 919
北恋
北恋 2020-12-17 15:10

I have a few instances where I place image within a link. Normally if you set border=\"0\" there line under a link does not apply to the image. However, I had to specify DOC

相关标签:
8条回答
  • 2020-12-17 15:23

    In case anyone cares, here's an alternative solution that I came up with to circumvent the issue:

    .nl {
        text-decoration:none;
    }
    <a href="link.php" class="nl"><img src="img.png" height="16" width="16" border="0"><u>link</u></a>

    0 讨论(0)
  • 2020-12-17 15:24

    Solved

    <a href="link.php" style="text-decoration: none"><img src="img.png" height="16" width="16" border="0"> link</a> 
    
    0 讨论(0)
  • 2020-12-17 15:28

    If you are linking to an image, try the following:

    a[href$=jpg], a[href$=png] {
        text-decoration: none;
    }
    
    0 讨论(0)
  • 2020-12-17 15:30
    a { text-decoration: none }
    

    The underline is from the A-tag not the IMG

    0 讨论(0)
  • 2020-12-17 15:31

    For those cases where editing the markup isn't an option (inaccessibility to templates and/or surrounding issues), you can use a little jQuery. You may need to adjust the syntax to override your CSS:

    jQuery('a > img').parent().css({'text-decoration' : 'none'});

    0 讨论(0)
  • 2020-12-17 15:34

    If you want to have a special case for links with images, give the a element a class and remove the text-decoration for that class:

    HTML:

    <a href="link.php" class="image-link"><img height="16" width="16" /></a>
    

    CSS:

    a img
    {
      border: 0 none;
    }
    .image-link
    {
      text-decoration: none;
    }
    

    This is great if you only have an image within the link, however you have both text and images within the anchor.

    The solution for that would be to add a span around the text within the anchor:

    <a href="link.php" class="image-link"><img height="16" width="16" /> <span>link text here</span></a>
    

    and add an additional style in the stylesheet:

    .image-link span
    {
      text-decoration: underline;
    }
    
    0 讨论(0)
提交回复
热议问题