Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Skip underline in part of link

Is it possible to have a contiguous link, where the text is normally underlined on mouse hover, but in the middle have a section (eg an image) without this underline? This does not work:

<a href="#">one <span style="text-decoration:none;">two</span> <img src="img.png" style="border:0px; text-decoration:none;"> three</a>
like image 352
Biggles Avatar asked Jun 04 '10 07:06

Biggles


2 Answers

Make a class that hides underlines, and child class that adds them.

.underline-some {
  text-decoration: none;
}

.underline-some:hover .text {
  text-decoration: underline;
}
<a href="#" class="underline-some">
  <span class="text">Boyz</span> 💈💈
  <span class="text">Men</span>
</a>

This example code above only underlines links on hover. For always-underlined links, remove :hover.

like image 134
Chad von Nau Avatar answered Oct 29 '22 04:10

Chad von Nau


a, a:hover { text-decoration: underline; }
a img, a:hover img { text-decoration: none !important; }
like image 21
eyelidlessness Avatar answered Oct 29 '22 04:10

eyelidlessness