此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

style

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

style 属性指定了指定其元素的样式信息。它的功能与 HTML 中的 style 属性相同。

使用环境

Categories Presentation attribute
Value <style>
Animatable No
<style>

样式数据的语法取决于样式表语言。默认情况下,如果未指定 contentStyleType,样式表语言为 CSS。

示例

以下示例展示了使用 CSS 作为样式表语言来使用 style 属性,为一个矩形框添加样式。

html
<svg version="1.1" viewbox="0 0 1000 500" xmlns="http://www.w3.org/2000/svg">
  <rect
    height="300"
    width="600"
    x="200"
    y="100"
    style="fill: red; stroke: blue; stroke-width: 3" />
</svg>

元素

以下元素可以使用 style 属性

规范

规范
Scalable Vector Graphics (SVG) 2
# ElementSpecificStyling

相关