<style>
.svg-box{position: relative;
}
.svg-box img{opacity: 0;
}
.svg-box .svg-icon{position: absolute;left: 0;top: 0;width: 100%;height: 100%;
}
</style><div class="svg-box"><img src="multiple.png" width="100%"/><svg width="198" height="206" viewBox="0 0 198 206" fill="none" xmlns="" class="svg-icon"><rect x="8.5" y="24.5" width="181" height="181" rx="3.5" fill="#fff" stroke="#E6007A"/><rect x="4.5" y="12.5" width="189" height="189" rx="3.5" fill="#fff" stroke="#E6007A"/><rect x=".5" y=".5" width="197" height="197" rx="3.5" fill="#fff" stroke="#E6007A"/><path fill-rule="evenodd" clip-rule="evenodd" d="M113.142 113.142c7.811-7.81 7.811-20.474 0-28.284-7.81-7.81-20.474-7.81-28.284 0-7.81 7.81-7.81 20.474 0 28.284 7.81 7.811 20.474 7.811 28.284 0zM109 99a2 2 0 0 1-2 2h-6v6a2 2 0 0 1-4 0v-6h-6a2 2 0 0 1 0-4h6v-6a2 2 0 1 1 4 0v6h6a2 2 0 0 1 2 2z" fill="#E6007A"/></svg>
</div>
后来发现 去掉透明 img 和定位,仍然有效,代码见下方解决方法
HTML
<div class="svg-box"><svg width="198" height="206" viewBox="0 0 198 206" fill="none" xmlns="" class="svg-icon"><rect x="8.5" y="24.5" width="181" height="181" rx="3.5" fill="#fff" stroke="#E6007A"/><rect x="4.5" y="12.5" width="189" height="189" rx="3.5" fill="#fff" stroke="#E6007A"/><rect x=".5" y=".5" width="197" height="197" rx="3.5" fill="#fff" stroke="#E6007A"/><path fill-rule="evenodd" clip-rule="evenodd" d="M113.142 113.142c7.811-7.81 7.811-20.474 0-28.284-7.81-7.81-20.474-7.81-28.284 0-7.81 7.81-7.81 20.474 0 28.284 7.81 7.811 20.474 7.811 28.284 0zM109 99a2 2 0 0 1-2 2h-6v6a2 2 0 0 1-4 0v-6h-6a2 2 0 0 1 0-4h6v-6a2 2 0 1 1 4 0v6h6a2 2 0 0 1 2 2z" fill="#E6007A"/></svg>
</div>
CSS
:root{--mainColor: #e6007a;
}
.svg-box .svg-icon{width: 100%;height: 100%;
}
.svg-icon rect{stroke:var(--mainColor);
}
.svg-icon path{fill:var(--mainColor);
}
JS: 修改主题色
let root = document.querySelector(":root");
root.style.setProperty("--mainColor", '你想设置的主题颜色,如:#3498db');
本文发布于:2024-01-27 19:52:38,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063563602294.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |