Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove line under image in link

Tags:

html

css

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 DOCTYPE to be and now in FF I see the line under all images.

I still would like to have my links underlined, but not the images within.

<a href="link.php"><img src="img.png" height="16" width="16" border="0"> link</a> 

I've tried to solve it with CSS by adding

a img {
    text-decoration:none
}

Unfortunately it did not work. I also tried:

a img {
    border:0
}

IE does not "underline" my images within a link... Any suggestions would be highly appreciated.

Example Link

enter image description here

I still would like to have my links underlined, but not the images within.

like image 367
santa Avatar asked Jan 24 '11 18:01

santa


People also ask

Which property can remove the underline from link?

To remove the underline from links, you can use the CSS text-decoration property.

How do you make a link without an underline in HTML?

You can do so anywhere in the <body></body> tag to make the link not have an underline. Defining a style property this way is called inline styling. The style is specified "inline," in the element itself, in the body of your page.


1 Answers

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;
}
like image 83
zzzzBov Avatar answered Sep 21 '22 12:09

zzzzBov