CSS 通用选择器不适用于 SVG

问题描述 投票:0回答:1
css svg selector
1个回答
0
投票

因为id选择器具有更高的优先级。

:root {
  --norm-colour: green;
  --high-colour: red;
}

[id^="btn"] {
  position: absolute;
  width: 15%;
  color: var(--norm-colour);
}

[id^="btn"]:hover {
  color: var(--high-colour);
  cursor: pointer;
}
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
        <g id="repeat">
            <path fill="currentColor" d="M20.3 13.43a1 1 0 0 0-1.25.65A7.14 7.14 0 0 1 12.18 19A7.1 7.1 0 0 1 5 12a7.1 7.1 0 0 1 7.18-7a7.26 7.26 0 0 1 4.65 1.67l-2.17-.36a1 1 0 0 0-1.15.83a1 1 0 0 0 .83 1.15l4.24.7h.17a1 1 0 0 0 .34-.06a.33.33 0 0 0 .1-.06a.78.78 0 0 0 .2-.11l.09-.11c0-.05.09-.09.13-.15s0-.1.05-.14a1.34 1.34 0 0 0 .07-.18l.75-4a1 1 0 0 0-2-.38l-.27 1.45A9.21 9.21 0 0 0 12.18 3A9.1 9.1 0 0 0 3 12a9.1 9.1 0 0 0 9.18 9A9.12 9.12 0 0 0 21 14.68a1 1 0 0 0-.7-1.25Z" />
        </g>
    </svg>
<svg id="btnRepeat" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="button">
        <use href="#repeat"></use>
    </svg>

© www.soinside.com 2019 - 2024. All rights reserved.