简体   繁体   English

如何设置图标的背景颜色以及如何在cs上悬停在li背景颜色上时也使用css获得与图标背景颜色相同的颜色

[英]How to set background-color of icon and when hover on li background color also get same color with icon background color using css

I want to set background-color of icon grey color and whenever i hover on li background-color of "li" also get grey color but the CSS which i have defined it is not working how to do that ? 我想将图标的背景色设置为灰色,并且每当我将鼠标悬停在li上时,li的背景色也将变为灰色,但是我定义的CSS无法正常工作该怎么做?

 .main-menu li .fa-home, .main-menu li.apps1:hover { background-color: grey; } 
 <link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" /> <ul class="main-menu"> <li class="apps1"> <a href="#"> <span class="fa fa-home"></span> <span class="text">Dashboard</span> </a> </li> </ul> 

The below will apply the grey background to the li element when it is hovered. 悬停在li元素上时,以下将灰色背景应用于li元素。 Since the icon is a child of this element, it will appear to have a grey background as well. 由于图标是该元素的子元素,因此它也将显示为灰色背景。

 .main-menu li:hover { background-color: grey; } .main-menu li a .fa { color: grey; } 
 <link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" /> <ul class="main-menu"> <li class="apps1"> <a href="#"> <span class="fa fa-home"></span> <span class="text">Dashboard</span> </a> </li> </ul> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM