hello friends please I am using the styled component for my react project and have been stuck for days now while trying to add a hover effect to the icons in my header component. i would appreciate if anyone can help on how to target and add the hover effect to the header icons
Below is the styling as you can seein the media query i am trying to target and add a hover effect on the header icon but i am unable
<NabList >
<a>
<img src = "./images/nav-network.svg"
alt = "" />
<span > Network </span>
</a>
</NabList>
const NabList = styled.li `
display: flex;
align-items: center;
font-size: 14px;
justify-content:center;
a{
align-items:center;
background-color: transparent;
display:flex;
flex-direction: column;
font-weight: 400;
font-weight: 12px;
line-height: 1.5;
min-width: 20px;
max-height: 42px;
text-decoration: none;
margin-top:4px;
padding:0 5px;
span{
display:flex;
align-items: center;
color : rgba(0, 0, 0, 0.6);
padding-left: 10px;
};
}
@media (max-width: 768px) {
a{
padding:0 !important;
}
padding:0 2px;
span{
margin-right:5px;
text-align:center;
font-size:13px;
};
img{
width:15px;
&:last-child{
width:12px;
}
}
}
&:hover{
a{
span{
color:rgba(0, 0, 0, 0.9);
}
}
}
3
Answers
able to apply hover effect on icon
checkout it out example
pls hover setting icon
example
in here, you need to go down selector
just place
&:hover
selector outside thea
selector to target the entire NabList component when hovered:If you want to modify svgs I would suggest making them react components, and reading up on how to work with SVGs in react. I’ve used https://react-svgr.com/playground/ to convert svgs to react components, but I think you can do something a little simpler like this:
Then replace the image element with
Then to change opacity:
Or this if you want to update the element when the container is hovered.