1. 面向开发者的 Web 技术
  2. Web API
  3. CSSImageValue

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

View in English Always switch to English

CSSImageValue

有限可用

此特性不属于基线,因为它尚未在主流浏览器中得到支持。

Want more support for this feature? Tell us why.

CSS 类型对象模型 APICSSImageValue 接口表示取用图像的属性(例如 background-imagelist-style-imageborder-image-source)的值。

CSSImageValue 对象表示涉及 URL(如 url()image(),但不包括 linear-gradient()element())的 <image>

CSSStyleValue CSSImageValue

实例属性

无。

实例方法

继承 CSSStyleValue 的方法。

示例

创建元素

html
<button>魔杖</button>

我们添加了一些 CSS,包括请求二进制文件的背景图片:

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

我们获取元素的样式映射。然后,我们从样式映射中获取(get())背景图片(background-image),并将其字符串化:

js
// 获得元素
const button = document.querySelector("button");
// 使用 computedStyleMap() 读取所有已计算的样式
const allComputedStyles = button.computedStyleMap();
// 返回 CSSImageValue 示例
console.log(allComputedStyles.get("background-image"));
console.log(allComputedStyles.get("background-image").toString());

规范

规范
CSS Typed OM Level 1
# imagevalue-objects

浏览器兼容性

参见

帮助改进 MDN

了解如何参与贡献

此页面最后更新于 ,由 MDN 贡献者更新。

AltStyle によって変換されたページ (->オリジナル) /