list-style-image

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

list-style-image CSS 属性用于设置一个图片作为列表项标记。

通常使用简写属性 list-style 会更方便。

试一试

list-style-image: url("/shared-assets/images/examples/rocket.svg");
list-style-image: none;
<section class="default-example" id="default-example">
  <div>
    <p>NASA Notable Missions</p>
    <ul class="transition-all unhighlighted" id="example-element">
      <li>Apollo</li>
      <li>Hubble</li>
      <li>Chandra</li>
      <li>Cassini-Huygens</li>
      <li>Spitzer</li>
    </ul>
  </div>
</section>
.default-example {
  font-size: 1.2rem;
}

#example-element {
  width: 100%;
  background: #be094b;
  color: white;
}

section {
  text-align: left;
  flex-direction: column;
}

hr {
  width: 50%;
  color: lightgray;
  margin: 0.5em;
}

.note {
  font-size: 0.8rem;
}

.note a {
  color: #009e5f;
}

@counter-style space-counter {
  symbols: "\1F680" "\1F6F8" "\1F6F0" "\1F52D";
  suffix: " ";
}

注意:此属性应用于列表项,即 display: list-item; 的元素。 默认情况下,这包括 <li> 元素。由于此属性是可继承的,因此可以将其设置在父元素上(通常是 <ol><ul>),以使其应用于所有列表项。

语法

css
/* Keyword values */
list-style-image: none;

/* <url> values */
list-style-image: url("star-solid.gif");

/* valid image values */
list-style-image: linear-gradient(to left bottom, red, blue);

/* Global values */
list-style-image: inherit;
list-style-image: initial;
list-style-image: revert;
list-style-image: revert-layer;
list-style-image: unset;

<image>

用作标记的有效图像。

none

指定不使用任何图像作为标记。如果设置此值,则将使用 list-style-type 中定义的标记。这是 list-style 的默认值。

正式定义

初始值none
应用于列表项
继承性
计算值关键字 none 或计算出的 <image>
动画类型离散

正式语法

list-style-image = 
<image> |
none

<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>

<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )

<image-set()> =
image-set( <image-set-option># )

<cross-fade()> =
cross-fade( <cf-image># )

<element()> =
element( <id-selector> )

<image-tags> =
ltr |
rtl

<image-src> =
<url> |
<string>

<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?

<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?

<id-selector> =
<hash-token>

示例

使用 URL 值

此示例使用星形作为标记,我们通过 <url> 图像函数将其包含在内。

HTML

html
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

CSS

css
ul {
  list-style-image: url("star-solid.gif");
}

结果

使用渐变

此示例使用 CSS 渐变 作为标记,我们通过 linear-gradient() 图像函数创建它。

HTML

html
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

CSS

css
ul {
  font-size: 200%;
  list-style-image: linear-gradient(to left bottom, red, blue);
}

结果

规范

规范
CSS 列表与计数器模块第 3 级
# 图像标记

浏览器兼容性

另见