我正在尝试使用 CSS 来控制 .svg 文件的颜色。我使用 html 来调用 svg。我页面上的颜色由 .php 控制(其他所有内容都在 .php 中)。我确信我一定错过了一个步骤,因为我无法获取颜色 php 页面来控制 svg。
<div class="headerPhoto">
<img src="images/icon.svg">
</div>
<rect class="iconRect" x="-7.7" y="-6.37" width="234.25" height="233.795" />
<g>
<path d="M119.575,125.577l-22.755,44.607l-71.538,-0.213l58.744,-115.155l35.549,70.761ZM46.732,156.877l42.041,0.125l16.054,-31.47l-20.891,-41.585l-37.204,72.93Z" style="fill:#383b40;"/>
<path d="M199.718,169.971l-71.538,0.213l-22.755,-44.607l35.549,-70.761l58.744,115.155ZM120.173,125.532l16.054,31.47l42.041,-0.125l-37.204,-72.93l-20.891,41.585Z"/>
</g>
<path d="M240.789,48.355c0,-35.402 -28.742,-64.144 -64.144,-64.144l-128.29,0c-35.402,0 -64.144,28.742 -64.144,64.144l0,128.29c0,35.402 28.742,64.144 64.144,64.144l128.29,0c35.402,0 64.144,-28.742 64.144,-64.144l0,-128.29Z" style="fill:none;stroke-width:47.37px;stroke:#fff;"/>
<?php
header('content-type: text/css;');
$color1 = $colorDarkGreen;
$color2 = $colorWhite;
$color3 = $colorGray;
?>
.iconRect {fill:<?=$color2?>;}
我可以直接更改 .svg 文件中的样式值,但无法使外部样式表正常工作。
我不确定我缺少什么,任何帮助都会很棒!