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

View in English Always switch to English

media

基线 广泛可用

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

media 属性指定只有符合media query的样式表才会被应用。

只有一个元素使用这个属性: <style>

示例

html
<svg viewBox="0 0 240 220" xmlns="http://www.w3.org/2000/svg">
  <style>
    rect {
      fill: black;
    }
  </style>
  <style media="all and (min-width: 600px)">
    rect {
      fill: seagreen;
    }
  </style>

  <text y="15">Resize the window to see the effect</text>
  <rect y="20" width="200" height="200" />
</svg>

Usage notes

Value <media-query-list>
Default value all
Animatable Yes
<media-query-list>

This value holds a media query that needs to match in order for the style sheet to be applied.如果没有指定,样式表就会被应用。

规范

规范
Scalable Vector Graphics (SVG) 2
# StyleElementMediaAttribute

浏览器兼容性