【发布时间】:2017-07-02 19:02:49
【问题描述】:
我有一个生成的 svg 路径代码,我想用 CSS 文件覆盖它以更改 svg 形状。 我可以覆盖除“d”之外的所有属性:
这里是生成的代码(我不能直接改):
<div id="map_outer" style="position: absolute; left: 3px; z-index: 1;">
<svg height="35" version="1.1" width="35" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative;"><desc style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Created with Raphaël 2.1.0</desc>
<defs style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
</defs>
<path fill="#cecece" stroke="#808080" d="M503.7,743.8C694,647.1999999999999,636.6,326.74999999999994,348.1,334.09V205.39L120.00000000000003,400.39L348.1,606.19V474.59000000000003C589,469.09000000000003,578,677.3900000000001,503.70000000000005,743.8900000000001Z" stroke-width="40" stroke-opacity="1" fill-opacity="1" transform="matrix(0.05,0,0,0.05,-1.9,-5.7)" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); stroke-opacity: 1; fill-opacity: 1; cursor: pointer;">
</path>
</svg>
</div>
这是覆盖d值的CSS,我明白了
未知属性名称
在 CSS 检查器中!!! :
#map_outer svg path{
fill: rgb(255, 204, 0) !important;
d:"M 850 300 C 850 300 350 300 350 300 L 348.1 205.39 L 120 400.39 L 348.1 606.19 L 350 500 C 850 500 850 500 850 500 z" !important;
stroke-width: 0;
}
【问题讨论】:
-
你不能用 CSS 做到这一点。 CSS 不是为此而设计的。您将不得不使用 JavaScript,然后该过程变得微不足道。如果您需要为此使用 CSS 选择器,请尝试使用 jQuery。
-
你确定任何 UI 都支持 d 作为 CSS 属性吗?此 Chrome 错误仍在进行中:bugs.chromium.org/p/chromium/issues/detail?id=652822。我认为你甚至超越了这里的前沿。
-
@MuhammadUsman 在 JS 或 JQuery 中有什么办法吗?
-
不幸的是,这在 FF 中不起作用