/    Sign up×
Community /Pin to ProfileBookmark

Getting rid of link underline in Firefox?

On my site I’m putting links around some images, like this page:
[url]http://www.girlscoutsmoheartland.org/pages/shop.php[/url]
where the HTML looks like this example:

[code=html]<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 />[/code]

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!

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@Big_O_1_Feb 23.2011 — 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.
Copy linkTweet thisAlerts:
@mechphistoauthorFeb 23.2011 — 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.[/QUOTE]

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! ?
Copy linkTweet thisAlerts:
@Big_O_1_Feb 23.2011 — 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.
    Copy linkTweet thisAlerts:
    @Big_O_1_Feb 23.2011 — 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.
    Copy linkTweet thisAlerts:
    @mechphistoauthorFeb 23.2011 — 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.[/QUOTE]

    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!! ?
    Copy linkTweet thisAlerts:
    @maxialbertMar 12.2011 — 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 />[/CODE]
    .... and the line on the bottom of your image will be gone.
    Copy linkTweet thisAlerts:
    @OctoberWindMar 17.2011 — Try This:

    (Tested via FireBug only, but should work across the board)

    [code=html]
    /* 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;}
    [/code]


    You might be able to get around the display: inline-block if your text was inside block-level <p> tags to begin with.
    ×

    Success!

    Help @mechphisto spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...