media

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Das media-Attribut gibt eine Media Query an, die erfüllt sein muss, damit ein Stylesheet angewendet wird.

Sie können dieses Attribut mit den folgenden SVG-Elementen verwenden:

Beispiel

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>

Verwendungshinweise

Wert <media-query-list>
Standardwert all
Animierbar Nein
<media-query-list>

Dieser Wert enthält eine Media Query, die erfüllt sein muss, damit das Stylesheet angewendet wird.

Wenn nicht angegeben, wird das Stylesheet bedingungslos angewendet.

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# StyleElementMediaAttribute

Browser-Kompatibilität