width
width 属性在用户坐标系统中定义了元素的一个水平长度。
你可以在以下 SVG 元素中使用该属性:
<feBlend><feColorMatrix><feComponentTransfer><feComposite><feConvolveMatrix><feDiffuseLighting><feDisplacementMap><feDropShadow><feFlood><feGaussianBlur><feImage><feMerge><feMorphology><feOffset><feSpecularLighting><feTile><feTurbulence><filter><foreignObject><image><mask><pattern><rect><svg><use>
示例
html
<svg viewBox="0 0 100 300" xmlns="http://www.w3.org/2000/svg">
<!-- With a width of 0 or less, nothing will be rendered -->
<rect x="0" y="0" width="0" height="90" />
<rect x="0" y="100" width="60" height="90" />
<rect x="0" y="200" width="100%" height="90" />
</svg>
use
对于 <use> 元素,width 定义了引用元素的水平长度。
| 值 |
auto |
<length>
|
<percentage>
|
|---|---|
| 默认值 | auto(视为 0) |
| 可变性 | 是 |
备注:
width 对 use 元素没有影响,除非引用的元素具有 viewBox。例如,该属性仅在 use 引用的元素是 svg 或 symbol 元素时才有意义。
备注:
从 SVG2 开始,width 变为几何属性,这意味着该元素也可以用作使用的元素的 CSS 属性。