What I need is for the SVG to disappear but the drop shadow to remain on hover. What I’m getting is both the SVG and the drop shadow disappearing.
div > svg {
color: black;
filter: drop-shadow(0px 0px 6px red);
}
div:hover > svg {
color: transparent;
}
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<g id="ico">
<path fill="currentColor"
d="M20.3..." />
</g>
</svg>
<div>
<svg style="background-color: transparent;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="button">
<title>A title here</title>
<use href="#ico"></use>
</svg>
</div>
How can I change my CSS to get what I need?
2
Answers
You can try
color:white
instead oftransparent
The problem is that the drop-shadow CSS filter uses the alpha channel of the input under the covers and relies on that being non-zero. When you set its opacity to 0 – the drop-shadow disappears.
So you have to customize the SVG filter that is doing the work under the covers. This turns out to be slightly tricky. You have to set the opacity of the hover color to almost zero – but non zero, and then use the filter to dial it back to normal (the 100 in that color matrix), so that you still have an opaque shape to feed into the dropshadow part of the filter.