When hovering over a specific area designated by the <a>
tag, I want the icon's color to change. However, despite my efforts, the color remains the same unless I hover directly over the icon using the following CSS code:
.sidebar .menu li a .icon:hover{background: #ecedf2;color: #3d5654;}
This means that I have to precisely hover over the icon itself in order to see the desired effect. My goal is to change the icon's color while hovering over the entire <a>
tag area. Please advise if there are any errors in my approach.
HTML
<div class="sidebar">
<ul class="menu">
<li>
<a href="#"
><span class="icon"><i class="fas fa-desktop"></i></span
><span class="text">Dashboard</span></a
>
</li>
</ul>
</div>
CSS
* {
list-style: none;
text-decoration: none;
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Jost', sans-serif;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
height: 100vh;
width: 100wh;
padding: 0;
margin: 0;
font-size: 1rem;
font-weight: 300;
line-height: 1.6;
display: grid;
grid-template-columns: auto 8fr;
grid-template-rows: 80px auto 50px;
grid-template-areas:
'header header'
'sidebar main'
'footer footer';
}
.sidebar {
grid-area: sidebar;
width: 260px;
background: #2c343b;
height: 100%;
}
.sidebar .menu {
padding-right: 30px;
padding-left: 20px;
margin: 0;
overflow: auto;
transition: all 0.5s;
}
.sidebar .menu li a {
color: #ecedf2;
display: block;
width: 100%;
line-height: 60px;
text-decoration: none;
padding: 15px;
text-transform: uppercase;
letter-spacing: 2px;
margin-bottom: 1px;
transition: 0.5s;
}
.sidebar .menu li a .icon {
color: #ecedf2;
width: 25px;
display: inline-block;
}
.sidebar .menu li a:hover,
.sidebar .menu li a.active {
background: #ecedf2;
color: #3d5654;
}