Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

html - Remove line under image in link

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...