简体   繁体   English

悬停时更改svg的颜色

[英]Change color of svg on hover

I have two svg items, one for a + sign and one for a minus sign. 我有两个svg项,一个为+号,一个为负号。 I want to turn them both white on hover, but it doesn't work, here is the html: 我想在悬停时将它们都变成白色,但这不起作用,这是html:

 zoom-control svg g path:hover { color: white; } 
 <div> <zoom-control class="first-btn" :isFirst="true" :handler="attachZoomInHandler"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> <g fill="none" fill-rule="evenodd" stroke="#00A6CE" stroke-linecap="round" stroke-width="2"> <path d="M18 12H6M12 18V6"/> </g> </svg> </zoom-control> <zoom-control class="last-btn" :isLast="true" :handler="attachZoomOutHandler"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> <path fill="none" fill-rule="evenodd" stroke="#00A6CE" stroke-linecap="round" stroke-width="2" d="M18 12H6"/> </svg> </zoom-control> </div> 

Why is it not working and how can I turn them white on hover? 为什么它不起作用,如何在悬停时将它们变白?

You need to change the css selection a bit for it to work: 您需要稍微更改css选择才能使其工作:

 zoom-control svg:hover path { stroke: white; } 
 <div> <zoom-control class="first-btn" :isFirst="true" :handler="attachZoomInHandler"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> <g fill="none" fill-rule="evenodd" stroke="#00A6CE" stroke-linecap="round" stroke-width="2"> <path d="M18 12H6M12 18V6"/> </g> </svg> </zoom-control> <zoom-control class="last-btn" :isLast="true" :handler="attachZoomOutHandler"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> <path fill="none" fill-rule="evenodd" stroke="#00A6CE" stroke-linecap="round" stroke-width="2" d="M18 12H6"/> </svg> </zoom-control> </div> 

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

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