[英]An SVG component inside an "i" element doesn't change color when the div is on hover
I want the "icons" to turn yellow on hover just like the text but it only worked when i put .navbar-list-item i:hover
.我希望“图标”在 hover 上变成黄色,就像文本一样,但它只在我放置.navbar-list-item i:hover
。 In that case it changes the color ONLY when the icon itself is on hover, not the div that has it.在这种情况下,它仅在图标本身位于 hover 时才更改颜色,而不是包含它的 div。
It happens because I have a default color set earlier.发生这种情况是因为我之前设置了默认颜色。
CSS: CSS:
.navbar-list-item:hover{
background-color: rgb(0, 0, 0);
color: #F3D63B;
transition: color 0.1s, background-color 0.3s;
}
HTML: HTML:
<nav class="navbar">
<ul class="navbar-list">
<a href="/">
<li class="navbar-list-item">
<i class="fa-solid fa-lemon"></i>
</li>
</a>
<li class="navbar-list-item">Item 1</li>
<li class="navbar-list-item">Item 2</li>
<li class="navbar-list-item">Item 3</li>
<li class="navbar-list-item">
<i class="fa-solid fa-cart-shopping"></i>
</li>
</ul>
</nav>
So basically I just had to add .navbar-list-item:hover i
in the same CSS snippet and it works.所以基本上我只需要在同一个 CSS 片段中添加.navbar-list-item:hover i
就可以了。
Here's what it looks like:这是它的样子:
.navbar-list-item:hover, .navbar-list-item:hover i{
background-color: rgb(0, 0, 0);
color: #F3D63B;
transition: color 0.1s, background-color 0.3s;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.