2016-12-02 135 views

回答

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

能也可以使用'a.boost_author:懸停span.boost_author戶名{} '?如果是這樣,最常見的事情是什麼?我是否還需要使用'a.'和'span.'? – Engo

+0

那麼我不能評論具體的類名稱,但是,如果你想要整個元素的集合是一個可點擊的鏈接,但只有鏈接的文字部分懸停下劃線,那麼我提供的技術是規範。 – Utkanos

+0

我想只爲我的網站的特定部分添加此規則。爲什麼它是'a:hover'而不是'boost_author:hover'? – Engo

2

使用text-decoration<span>a:hover財產。

在下面的代碼片段看一看:

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>

希望這有助於!

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

對於我的理解,是否'a:hover span.b_author-username'的意思是:對於類名爲'b_author-username'的所有跨度(使用僞類懸停)應用樣式'text-decoration:underline'? – Engo

+0

'a'和'span'是強制性的嗎?用類名代替它會更好嗎? – Engo

+0

@Engo是的,我只限於跨度和錨定標籤。不要使用這個,如果你的類有一個全局作用域,這意味着任何東西都可以使用這個類 –

相關問題