CSSImageValue - Web-APIs | MDN

Instanz-Eigenschaften

Keine.

Instanz-Methoden

Erbt Methoden von CSSStyleValue.

Beispiele

Wir erstellen ein Element

html

<button>Magic Wand</button>

Wir fügen etwas CSS hinzu, einschließlich eines Hintergrundbilds, das eine Binärdatei anfordert:

css

button {
  display: inline-block;
  min-height: 100px;
  min-width: 100px;
  background: no-repeat 5% center url("magic-wand.png") aqua;
}

Wir erhalten die Stilkarte des Elements. Dann rufen wir get() für das Hintergrundbild von der Stilkarte auf und konvertieren es in einen String:

js

// get the element
const button = document.querySelector("button");

// Retrieve all computed styles with computedStyleMap()
const allComputedStyles = button.computedStyleMap();

// Return the CSSImageValue Example
console.log(allComputedStyles.get("background-image"));
console.log(allComputedStyles.get("background-image").toString());

Spezifikationen

Spezifikation
CSS Typed OM Level 1
# imagevalue-objects

Browser-Kompatibilität

Siehe auch

Help improve MDN

Erfahren Sie, wie Sie beitragen können Diese Seite wurde automatisch aus dem Englischen übersetzt.