Jump to content

[SOLVED] Link problem - using both image and text


vineld

Recommended Posts

I have run into problems formatting links and am wondering how to solve this:

 

<div>
   <a href=""><img src="" /><br />[LINK TEXT]</a>
</div>

 

I have styled links to be underlined and normal when hovered. Now, the above situation results in the image being underlined as well since it is a line within the link. This I do not want.

 

How should I solve this in the best manner so that the images are not underlined? I do not wish to have two separate links since that would not be good SEO-wise.

Link to comment
Share on other sites

Hmm. Add something to the stylesheet. You're going to want to single out the image element in your css. I would probably start by giving the div an id or class. So the stylesheet info would look like this if you gave the div an id of "blah":

 

 

#blah a img{text-decoration:none;}

 

I'm not fully sure if that would work to be honest. If not:

 

 

#blah a img, #blah a img:hover{text-decoration:none;}

Link to comment
Share on other sites

That should work fine.

 

But honestly, I don't think that there is any SEO penalty for having a text link as well as an image link (though I'm only an SEO intermediate, not a pro by any means), so I think separate links would be fine.

 

You could also wrap the text inside the link with span tags, and use them for the styling.

Link to comment
Share on other sites

No, adding text-decoration:none; on the image does not work since I don't think the underline is for the image itself but for that line of text before the line break. display: block works but I do not wish to use that...

Link to comment
Share on other sites

It doesn't, really, although I just can't get this to work:

 

a:hover span
{
text-decoration: none;
color: green;
}

 

I don't wish the text to end up green although this was only for testing. This will make the text green although the underline remains. I have searched the css file and can't find any other rules that would override this one...

 

I have a feeling my brain isn't working well today =)

Link to comment
Share on other sites

Either this is a misunderstanding or I'm completely lost  :-[

 

What you say is that I should style the text within the link with e.g. a span to make it underlined? Then it will stay underlined no matter if I add a hover on the link tag itself since that will not affect the css added to the span.

Link to comment
Share on other sites

The normal state for all general links of the website is underline and none on hover. That is exactly what I want in this case as well. In the normal state the image should not be underlined (it has no borders so that is not the issue) but the link text should be. On hover the image should still not be underlined and neither should the link text.

 

What we have so far:

 

1. Styling the image will do no good.

 

2. Using two separate links + javascript would work but I would like to avoid this if possible.

 

3. Simply putting the link text in a span and add underline on this one will not help since it will not be affected by a change in the surrounding link tag.

 

The two separate links solution is beginning to sound very appealing to me though  8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.