简体   繁体   中英

Change background-color in svg-imge with text inside it

Image with some text inside it. On hover the svg changes background color except when hovering over the text inside it.

How can I make the svg-background change when hovering over the text also?

<svg class="svg">
    <polygon class="polygon" points="100,10 40,198 190,78 10,78 160,198">
    </polygon>
    <text class="number" x="85" y="115">456</text>
</svg>

.svg {

}
.svg .polygon {
   fill: red;
}
.svg .polygon:hover {
  fill: blue;
}
.svg .number {
  font-size: 19px;
}

https://jsfiddle.net/king_s/kcoetje0/

To achieve this, you need to add pointer-events: none; to your <text> tag.

CSS

.svg .number {
  font-size: 19px;
  pointer-events: none; /* <-- Add This */
}

JSFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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