width
width 属性定义了元素在用户坐标系中的水平长度。
元素
你可以在下面部分描述的 SVG 元素中使用此属性。
<feBlend>
对于 <feBlend>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feColorMatrix>
对于 <feColorMatrix>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feComponentTransfer>
对于 <feComponentTransfer>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feComposite>
对于 <feComposite>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feConvolveMatrix>
对于 <feConvolveMatrix>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feDiffuseLighting>
对于 <feDiffuseLighting>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feDisplacementMap>
对于 <feDisplacementMap>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feDropShadow>
对于 <feDropShadow>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feFlood>
对于 <feFlood>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feGaussianBlur>
对于 <feGaussianBlur>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feImage>
对于 <feImage>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feMerge>
对于 <feMerge>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feMorphology>
对于 <feMorphology>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feOffset>
对于 <feOffset>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feSpecularLighting>
对于 <feSpecularLighting>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feTile>
对于 <feTile>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<feTurbulence>
对于 <feTurbulence>,width 定义了原始元素的渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 100% |
| 可动画的 | 是 |
<filter>
对于 <filter>,width 定义了滤镜渲染区域的水平长度。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 120% |
| 可动画的 | 是 |
<foreignObject>
对于 <foreignObject>,width 定义了引用文档渲染区域的水平长度。
| 值 |
auto | <length> | <percentage> |
|---|---|
| 默认值 | auto(视为 0) |
| 可动画的 | 是 |
注意:从 SVG2 开始,width 是一个 几何属性,这意味着此属性也可以作为 <foreignObject> 的 CSS 属性使用。
<image>
对于 <image>,width 定义了图像的水平长度。
| 值 |
auto | <length> | <percentage> |
|---|---|
| 默认值 | auto(视为图像的固有宽度) |
| 可动画的 | 是 |
注意:从 SVG2 开始,width 是一个 几何属性,这意味着此属性也可以作为图像的 CSS 属性使用。
<mask>
对于 <mask>,width 定义了其作用区域的水平长度。此属性的具体效果受 maskUnits 属性的影响。
| 值 | <length> | <percentage> |
|---|---|
| 默认值 | 120% |
| 可动画的 | 是 |
<pattern>
对于 <pattern>,width 定义了平铺图案的水平长度。此属性的具体效果受 patternUnits 和 patternTransform 属性的影响。
| 值 | <length> |
|---|---|
| 默认值 | 0 |
| 可动画的 | 是 |
<rect>
对于 <rect>,width 定义了矩形的水平长度。
| 值 |
auto | <length> | <percentage> |
|---|---|
| 默认值 | auto(视为 0) |
| 可动画的 | 是 |
注意:从 SVG2 开始,width 是一个 几何属性,这意味着此属性也可以作为矩形的 CSS 属性使用。
<svg>
对于 <svg>,width 定义了 SVG 视口渲染区域的水平长度。
注意:在 HTML 文档中,如果 viewBox 和 width 属性都省略,svg 元素的宽度将渲染为 300px。
| 值 |
auto | <length> | <percentage> |
|---|---|
| 默认值 | auto(视为 100%) |
| 可动画的 | 是 |
注意:从 SVG2 开始,width 是一个 几何属性,这意味着此属性也可以作为 <svg> 的 CSS 属性使用。
<use>
对于 <use>,width 定义了引用元素的水平长度。
| 值 |
auto | <length> | <percentage> |
|---|---|
| 默认值 | auto(视为 0) |
| 可动画的 | 是 |
注意:width 对 use 元素没有影响,除非引用元素有 viewBox —— 也就是说,它们只在 use 引用 svg 或 symbol 元素时才有效。
注意:从 SVG2 开始,width 是一个 几何属性,这意味着此属性也可以作为已使用元素的 CSS 属性使用。
示例
此示例包含三个 <rect> 元素,其 width 属性值各不相同。第一个 <rect> 设置了 width="0"。宽度为 0 或更小的 SVG 元素不会被渲染。
<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"
fill="red"
stroke-width="5"
stroke="black" />
<rect
x="0"
y="100"
width="60"
height="90"
fill="red"
stroke-width="5"
stroke="black" />
<rect
x="0"
y="200"
width="100%"
height="90"
fill="red"
stroke-width="5"
stroke="black" />
</svg>
规范
另见
- CSS
width属性