CSS-悬停时显示mat-icon

前端之家收集整理的这篇文章主要介绍了CSS-悬停时显示mat-icon 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这个问题已经在这里有了答案:            >            What does the “+” (plus sign) CSS selector mean?                                    11个
>            What does the “>” (greater-than sign) CSS selector mean?                                    7个
我的html模板中有mat-list:

<mat-list *ngFor="let item of items">
  <mat-list-item><mat-icon>add</mat-icon> {{ item.title }}</mat-list-item>
</mat-list>

我只想在mat-list-item悬停时显示mat-icon.所以我想出了这个CSS:

mat-icon {
  display: none;
}

mat-list-item:hover + mat-icon {
  display: block;
}

但是由于某种原因它是行不通的

但是,如果我确实尝试更改背景颜色,则可以:

mat-list-item:hover {
  background-color: #3f51b5;
}

可能与mat-icon有关
有什么想法吗?

最佳答案
尝试这个

mat-icon{
  display: none;
}

mat-list-item:hover mat-icon{
  display: block;
}

您不需要+ adjacent selectors

demo

原文链接:https://www.f2er.com/css/530685.html

猜你在找的CSS相关文章