【问题标题】:font awesome: when use hover::before, the icon disappeared字体真棒:当使用 hover::before 时,图标消失了
【发布时间】:2019-08-04 18:25:17
【问题描述】:

我想悬停图标,这样它就会显示before 元素,但每次我悬停它时,图标都会消失,当我悬停图标的右半部分时,什么也没发生。如果我将before 更改为after,则效果很好。

.container {
    background-color: lightgray;
    margin: auto;
    width: 500px;
    height: 200px;
    padding: 100px;
}

.icon {
    font-size: 50px;
    cursor: pointer;
    color: red;
}

.icon:hover::before {
    content: '';
    background-color: black;
    padding: 10px;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">


<div class="container">
		<i class="fas fa-exclamation-circle icon"></i>
</div>

【问题讨论】:

  • 因为font awesome使用.fa-exclamation-circle::before来显示图标。您正在使用 .icon:hover::before 覆盖样式
  • 你想让它变黑吗?

标签: css font-awesome pseudo-element


【解决方案1】:

这将在悬停时添加黑色背景。你不能休息content,因为它被FontAwesome用来显示图标。

.container {
    background-color: lightgray;
    margin: auto;
    width: 500px;
    height: 200px;
    padding: 100px;
}

.icon {
    font-size: 50px;
    cursor: pointer;
    color: red;
}

.icon:hover::before {
    background-color: black;
    padding: 10px;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">


<div class="container">
		<i class="fas fa-exclamation-circle icon"></i>
</div>

【讨论】:

    猜你喜欢
    • 2015-02-24
    • 2014-02-08
    • 2014-01-16
    • 2020-09-11
    • 2013-12-07
    • 2017-05-02
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    相关资源
    最近更新 更多