我可以在 HTML 文件中使用 css 自定义 属性 吗?

Can I use a css custom property inside an HTML file?

是否可以在 HTML 标签内为内联 svg 元素使用 css 自定义 属性?

假设我有一个内联 svg 元素:

<svg style="width:var(--image-width);" />

现在,此声明无效,但有没有办法在 HTML 文件而不是 css 文件中使用 --image-width?

如果您导入定义 属性 --image-width.

的 css 文件,它应该可以工作

/* style.css */
:root {
    --image-width: 42px;
}
<!-- Your html file -->
<link rel="stylesheet" href="style.css">
<svg style="width: var(--image-width);">
    <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>