HTMLSourceElement: width-Eigenschaft

Die width-Eigenschaft des HTMLSourceElement-Interfaces ist eine nicht-negative Zahl, die die Breite der Bildressource in CSS-Pixeln angibt.

Die Eigenschaft hat nur eine Wirkung, wenn das übergeordnete Element des aktuellen <source>-Elements ein <picture>-Element ist.

Sie spiegelt das width-Attribut des <source>-Elements wider.

Wert

Eine nicht-negative Zahl, die die Breite der Bildressource in CSS-Pixeln angibt.

Beispiele

html
<picture id="img">
  <source
    srcset="landscape.png"
    media="(min-width: 1000px)"
    width="1000"
    height="400" />
  <source
    srcset="square.png"
    media="(min-width: 800px)"
    width="800"
    height="800" />
  <source
    srcset="portrait.png"
    media="(min-width: 600px)"
    width="600"
    height="800" />
  <img
    src="fallback.png"
    alt="Image used when the browser does not support the sources"
    width="500"
    height="400" />
</picture>
js
const img = document.getElementById("img");
const sources = img.querySelectorAll("source");
console.log(Array.from(sources).map((el) => el.width)); // Output: [1000, 800, 600]

Spezifikationen

Specification
HTML
# dom-dim-width

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
width

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch