html - 我可以在 HTML 文件中使用 css 自定义属性吗?
问题描述
是否可以在 HTML 标记中为内联 svg 元素使用 css 自定义属性?
假设我有一个内联 svg 元素:
<svg style="width:var(--image-width);" />
现在,此语句无效,但有没有办法在 HTML 文件中使用 --image-width 而不是 css 文件?
解决方案
如果您导入定义属性的 css 文件,它应该可以工作--image-width
。
/* 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>
推荐阅读
- google-apps-script - 无论如何,是否根据顶列值中的值突出显示谷歌表格中的整个列?
- javascript - DoubleTapToGo.js - 基于浏览器大小的绑定/取消绑定
- reactjs - 具有不同主题的 React 应用程序
- html - 实现静态 html 页面的国家 - 州 - 城市选择
- javascript - 将 xhr 转换为 .wav
- c++ - Lua C API 自定义打印函数,字符串中传入空格时不调用
- google-sheets - 如何根据另一个工作表中的列表过滤行?(谷歌表格)
- kubernetes - 如何从 Ansible 将变量传递给 Kubernetes YAML 文件?
- python - Beautiful Soup 4 Python 3.6.5 网络抓取,用于从英镑到美元的实时货币转换
- javascript - 尝试“放置”JSON 数据时出错