【发布时间】:2013-12-28 20:36:25
【问题描述】:
与How do I have an SVG image inherit colors from the HTML document? 相同的问题,但特别适用于用作:before 伪元素内容的svg 图像。
(期望的行为是两个复选标记都从正文继承红色。目前只有内联 SVG 可以。)
<style type='text/css'>
body {
color: red;
}
.checkmark {
height: 2em;
width: 2em;
}
.checkmark:before {
content: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%' viewBox='-0.5 0 20 15'><rect fill='currentColor' stroke='none' transform='rotate(45 4.0033 8.87436)' height='5' width='6.32304' y='6.37436' x='0.84178'></rect><rect fill='currentColor' stroke='none' transform='rotate(45 11.1776 7.7066)' width='5' height='16.79756' y='-0.69218' x='8.67764'></rect></svg>");
}
</style>
<!-- Renders red -->
<svg xmlns='http://www.w3.org/2000/svg' width='2em' height='2em' viewBox='-0.5 0 20 15'><rect fill='currentColor' stroke='none' transform='rotate(45 4.0033 8.87436)' height='5' width='6.32304' y='6.37436' x='0.84178'></rect><rect fill='currentColor' stroke='none' transform='rotate(45 11.1776 7.7066)' width='5' height='16.79756' y='-0.69218' x='8.67764'></rect></svg>
<!-- Renders #000 -->
<div class="checkmark"></div>
【问题讨论】: