【发布时间】:2021-07-05 14:03:40
【问题描述】:
我使用以下方法在 div 周围实现虚线边框:
div {
width: 100px;
height: 100px;
border-radius: 16px;
background-image: url('data:image/svg+xml,%3csvg stroke="black" width="100%25" height="100%25" xmlns="http://www.w3.org/2000/svg"%3e%3crect width="100%25" height="100%25" fill="none" rx="16px" ry="16px" stroke-width="6" stroke-dasharray="5%25%2c 2%25" stroke-dashoffset="4" stroke-linecap="butt"/%3e%3c/svg%3e');
}
<div></div>
是否可以用 CSS 变量替换 stroke 颜色 black?不幸的是,以下方法不起作用:
div {
--color: black;
background-image: url('data:image/svg+xml,%3csvg stroke="var(--color)" width="100%25" height="100%25" xmlns="http://www.w3.org/2000/svg"%3e%3crect width="100%25" height="100%25" fill="none" rx="16px" ry="16px" stroke-width="6" stroke-dasharray="5%25%2c 2%25" stroke-dashoffset="4" stroke-linecap="butt"/%3e%3c/svg%3e');
}
【问题讨论】:
标签: css svg css-variables