www.webdeveloper.com
Results 1 to 8 of 8

Thread: Getting rid of link underline in Firefox?

  1. #1
    Join Date
    Aug 2010
    Posts
    81

    Question Getting rid of link underline in Firefox?

    On my site I'm putting links around some images, like this page:
    http://www.girlscoutsmoheartland.org/pages/shop.php
    where the HTML looks like this example:
    HTML Code:
    <a href="/docs/shop/Shop Order Form.pdf" target="_blank"><img src="/images/files_tiny.gif" alt="retail form" width="18" height="19" border="0" align="absmiddle" />Use this one</a> for <strong>printing</strong> and filing out by hand,<br />
    The thing is, in Chrome and IE 7 and 8, the little image in the link shows no underline, which is what I want. But in Firefox, there's an annoying underline under the image.
    Unfortunately, we want the image next to the link to be linked as well, so I can't just move the image out of the anchor.
    Is there some CSS I can use to tell the browser don't underline a linked image?
    (I assume "text-decoration: none" would have no effect.)

    Thanks for any suggestions!

  2. #2
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    Is that your site that you have linked to? Because text-decoration: none worked for me in Firefox. It was in page-all.css line 481.

  3. #3
    Join Date
    Aug 2010
    Posts
    81
    Quote Originally Posted by Big O(1) View Post
    Is that your site that you have linked to? Because text-decoration: none worked for me in Firefox. It was in page-all.css line 481.
    Doh! I didn't make myself clear.
    The link text itself needs to stay underlined! (I'd prefer it wasn't, but I do what my boss says.) But the image needs to not have the underline (like it shows in IE and Chrome).
    Sorry for the confusion.
    Thanks for taking a look!

  4. #4
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    Oh, I see. Hmm.... If the image is part of the link, it will get the underline as well since it is a child of it. I can think of two solutions:

    1. Apply text-decoration: none to the <a>, and instead of using a regular image, use an image that includes the underline as a part of it. So in that example it will be that page icon with a line a little below it.
    2. Split up the <a> in two. So you will have <a><img><a> and right after it <a>text<a>. Apply text-decoration: none to just the second one. Make sure to give them both the same href. I prefer this method.

    These are just my ideas. If anybody has a better idea feel free to contribute.

  5. #5
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    Let me rephrase. I forgot you said you don't want the image to have an underline. So that means approach #1 gets thrown out the window, and approach #2 gets changed to applying text-decoration to just the first anchor.

  6. #6
    Join Date
    Aug 2010
    Posts
    81
    Quote Originally Posted by Big O(1) View Post
    Let me rephrase. I forgot you said you don't want the image to have an underline. So that means approach #1 gets thrown out the window, and approach #2 gets changed to applying text-decoration to just the first anchor.
    Thanks for the suggestion!
    That would work, but it would complicate things by requiring me to make sure I link twice which is a. something not easily remembered and b. clutters the HTML a bit. Also, it would mean having to also either put separate style or class attributes into the HTML.
    Instead, I just tried as a work-around, putting a -2px margin-bottom in the CSS. Seems to sorta solve that problem, and also puts the image more centered to the text so that's a plus.

    Not the most elegant solution, but it has the least side-effects.

    Thanks; I appreciate the reply!!

  7. #7
    Join Date
    Mar 2011
    Posts
    1
    This is a well known Firefox bug ... and unfortunately there isn't any coding solution in terms of CSS. All you can eventually do is just sort of a workaround. Set text-decoration: none; to the anchor. Image (a img) should have border: none; Create a span class like .underline {text-decoration: underline;} and apply it to text only in your links. Somethink like this:
    Code:
    <a href="/docs/shop/Shop Order Form.pdf" target="_blank"><img src="/images/files_tiny.gif" alt="retail form" width="18" height="19" border="0" align="absmiddle" /><span class="underline">Use this one</span></a> for <strong>printing</strong> and filing out by hand,<br />
    .... and the line on the bottom of your image will be gone.

  8. #8
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    Try This:
    (Tested via FireBug only, but should work across the board)

    HTML Code:
    /* float the image left, and strip out the funky margin hack, which will likely only cause headaches down the road */
    #content .linkimg { float: left; margin: 0 10px 0 0;}
    
    /* and to correct the floated image */
    #content a {display: inline-block; text-decoration: underline;}
    You might be able to get around the display: inline-block if your text was inside block-level <p> tags to begin with.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles