如何仅在<a> element in CSS?

时间:2016-12-02 14:55:16

标签: html css twitter-bootstrap

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?

enter image description here

中为文本元素加下划线

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

text-decoration上使用a:hover的{​​{1}}属性。

请看下面的代码段:

<span>
a {
  text-decoration: none;
}

a span {
  text-decoration: underline;
}

希望这有帮助!

答案 2 :(得分:1)

仅限制类

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

这对许多其他元素来说,通用

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