组合:使用:悬停文本装饰的字体图标 [英] Combine :after with :hover for text-decoration of a font icon

查看:108
本文介绍了组合:使用:悬停文本装饰的字体图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何得到下划线只适用于a元素而不适用于:after?

How can one get the underline to only apply to the a element and not to the content of the :after?

下面的CSS可以控制颜色of:after元素on:hover。

With the CSS below one can control the color of an :after element on :hover. However, the text-decoration cannot be changed.

这里是jsfiddle来说明问题:

Here's the jsfiddle to illustrate the problem:

http://jsfiddle.net/JfGVE/500/

这里是CSS:

a {
    color: green;
    text-decoration: none;
}
a:hover {
    color: green;
    text-decoration: underline;
}
a:after {
    font-family: FontAwesome;
    content: "\f061";
}

a:hover:after {
    color: orange;
    text-decoration: none !important;
}


推荐答案

display:inline-block 将删除文本修饰< a>:

Setting the pseudo-element to display: inline-block will remove the text decoration:

a:after {
    font-family: FontAwesome;
    content: "\f061";
    display: inline-block;
}

下划线仍然适用于两者之间的空格, c $ c>& nbsp; ,但您可以抵消伪元素具有边距,而不是在HTML中加入空格

The underline will still apply to the space in between because you have an &nbsp;, though — you can prevent this by offsetting the pseudo-element with a margin instead of putting hard spaces in the HTML.

这篇关于组合:使用:悬停文本装饰的字体图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆