简体   繁体   中英

How to only underline <span> text element inside an <a> element in CSS?

I'm using Bootstrap and I have the following code:

<a class="b_author" href="#">
  <img class="b_author-avatar img-circle" src="/images/profile_photo.jpg" width="20" height="20">
  <span class="b_author-username">johndoe</span>
</a>

How can I get rid of the underline on hover ?

在此处输入图片说明

a:hover { text-decoration: none; }
a:hover span { text-decoration: underline; }

Use text-decoration property of a:hover on <span> .

Have a look at the snippet below:

 a { text-decoration: none; } a span { text-decoration: underline; } 
 <a class="boost_author" href="#"> <img class="boost_author-avatar img-circle" src="/images/profile_photo.jpg" width="20" height="20"> <span class="boost_author-username">johndoe</span> </a> 

Hope this helps!

Restricting the styles only for the classes

a.b_author{
  text-decoration: none;
}
a.b_author:hover span.b_author-username{
  text-decoration: underline;
}

And this for many others elements, general purpose

a{
  text-decoration: none;
}
a:hover span{
  text-decoration: underline;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM