字体很棒:使用 hover::before 时,图标消失了

font awesome: when use hover::before, the icon disappeared

我想将鼠标悬停在图标上以显示 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>

这将在悬停时添加黑色背景。你不能休息 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>