试一试
list-style-type: space-counter;
list-style-type: disc;
list-style-type: circle;
list-style-type: "\1F44D";
<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>
</ul>
</div>
<hr />
<div class="note">
<p>
<code>space-counter</code> is defined with
<a
href="//mdn.org.cn/docs/Web/CSS/@counter-style"
target="_parent"
><code>@counter-style</code></a
>
</p>
</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: " ";
}
标记的颜色将是 currentColor,与其所应用的元素的计算后 color 值相同。
只有少数元素(<li> 和 <summary>)的默认值为 display: list-item。但是,list-style-type 属性可以应用于任何 display 值为 list-item 的元素。此外,由于该属性是可继承的,因此可以将其设置在父元素上(通常是 <ol> 或 <ul>),以使其应用于所有列表项。
语法
/* Partial list of types */
list-style-type: disc;
list-style-type: circle;
list-style-type: square;
list-style-type: decimal;
list-style-type: georgian;
list-style-type: trad-chinese-informal;
list-style-type: kannada;
/* <string> value */
list-style-type: "-";
/* Identifier matching an @counter-style rule */
list-style-type: custom-counter-style;
/* Keyword value */
list-style-type: none;
/* Global values */
list-style-type: inherit;
list-style-type: initial;
list-style-type: revert;
list-style-type: revert-layer;
list-style-type: unset;
list-style-type 属性可以定义为以下任何一种:
- 一个
<custom-ident>值, - 一个
symbols()值, - 一个
<string>值,或 - 关键字
none。
请注意:
- 某些类型需要安装合适的字体才能按预期显示。
cjk-ideographic与trad-chinese-informal相同;它的存在是出于历史原因。
值
<custom-ident>-
一个与
@counter-style的值或预定义样式之一匹配的标识符 symbols()-
定义列表的匿名样式。
<string>-
指定的字符串将用作列表项的标记。
none-
不显示任何列表项标记。
disc-
实心圆(默认值)。
circle-
空心圆。
square-
实心方块。
decimal-
十进制数字,从 1 开始。
cjk-decimal-
汉字十进制数字。
decimal-leading-zero-
十进制数字,前面用 0 填充。
lower-roman-
小写罗马数字。
upper-roman-
大写罗马数字。
lower-greek-
小写古典希腊字母。
lower-alpha,lower-latin-
小写 ASCII 字母。
upper-alpha,upper-latin-
大写 ASCII 字母。
arabic-indic,-moz-arabic-indic-
阿拉伯-印度数字。
armenian-
传统亚美尼亚数字。
bengali,-moz-bengali-
孟加拉数字。
cambodian/khmer-
柬埔寨/高棉数字。
cjk-earthly-branch,-moz-cjk-earthly-branch-
汉字“地支”序数。
cjk-heavenly-stem,-moz-cjk-heavenly-stem-
汉字“天干”序数。
cjk-ideographic-
与
trad-chinese-informal相同。 devanagari,-moz-devanagari-
梵文数字。
ethiopic-numeric-
埃塞俄比亚数字。
georgian-
传统格鲁吉亚数字。
gujarati,-moz-gujarati-
古吉拉特数字。
gurmukhi,-moz-gurmukhi-
果鲁穆奇数字。
hebrew-
传统希伯来数字。
hiragana-
按字典顺序排列的平假名。
hiragana-iroha-
按伊吕波顺序排列的平假名。
japanese-formal-
用于法律或财务文件中的日语正式数字。这些汉字经过设计,使其无法被修改成另一个正确的汉字。
japanese-informal-
日语非正式数字。
kannada,-moz-kannada-
卡纳达数字。
katakana-
按字典顺序排列的片假名。
katakana-iroha-
按伊吕波顺序排列的片假名。
korean-hangul-formal-
韩语谚文数字。
korean-hanja-formal-
正式的韩语汉字数字。
korean-hanja-informal-
韩语汉字数字。
lao,-moz-lao-
老挝数字。
lower-armenian-
小写亚美尼亚数字。
malayalam,-moz-malayalam-
马拉雅拉姆数字。
mongolian-
蒙古数字。
myanmar,-moz-myanmar-
缅甸数字。
oriya,-moz-oriya-
奥里亚数字。
persian,-moz-persian-
波斯数字。
simp-chinese-formal-
简体中文正式数字。
simp-chinese-informal-
简体中文非正式数字。
tamil,-moz-tamil-
泰米尔数字。
telugu,-moz-telugu-
泰卢固数字。
thai,-moz-thai-
泰语数字。
tibetan-
藏语数字。
trad-chinese-formal-
繁体中文正式数字。
trad-chinese-informal-
繁体中文非正式数字。
upper-armenian-
传统大写亚美尼亚数字。
disclosure-open-
表示可展开构件(如
<details>)已展开的符号。 disclosure-closed-
表示可展开构件(如
<details>)已折叠的符号。
请参阅所有列表样式类型示例以查看上述值的实际效果。有关世界各地不同文化使用的所有可用计数器样式的详细信息,请参阅现成的计数器样式。
非标准扩展
Mozilla (Firefox) 支持一些带有 -moz- 前缀的预定义类型。
ethiopic-halehame:-moz-ethiopic-halehameethiopic-halehame-am:-moz-ethiopic-halehame-amethiopic-halehame-ti-er:-moz-ethiopic-halehame-ti-erethiopic-halehame-ti-et:-moz-ethiopic-halehame-ti-etethiopic-numeric:-moz-ethiopic-numerichangul:-moz-hangulhangul-consonant:-moz-hangul-consonanturdu:-moz-urdu
请参阅兼容性表格以查看哪些浏览器支持哪些扩展。
无障碍
如果有序或无序列表的 list-style-type 值为 none,Safari 将不会在无障碍树中将其识别为列表。这可以通过在列表的开始标签中添加 role="list" 来解决。要了解更多相关信息和潜在的解决方法,请参阅 list-style。
正式定义
正式语法
list-style-type =
<counter-style> |
<string> |
none
<counter-style> =
<counter-style-name> |
<symbols()>
<symbols()> =
symbols( <symbols-type>? [ <string> | <image> ]+ )
<symbols-type> =
cyclic |
numeric |
alphabetic |
symbolic |
fixed
<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>
示例
设置列表项标记
HTML
List 1
<ol class="normal">
<li>Hello</li>
<li>World</li>
<li>What's up?</li>
</ol>
List 2
<ol class="shortcut">
<li>Looks</li>
<li>Like</li>
<li>The</li>
<li>Same</li>
</ol>
CSS
ol.normal {
list-style-type: upper-alpha;
}
/* or use the shortcut "list-style": */
ol.shortcut {
list-style: upper-alpha;
}
结果
所有列表样式类型
HTML
<ol>
<li>Apollo</li>
<li>Hubble</li>
<li>Chandra</li>
<li>Cassini-Huygens</li>
<li>Spitzer</li>
</ol>
<h2>Choose a list style type:</h2>
<div class="container">
<label for="disc">
<input type="radio" id="disc" name="type" value="disc" />disc
</label>
<label for="circle">
<input type="radio" id="circle" name="type" value="circle" />circle
</label>
<label for="square">
<input type="radio" id="square" name="type" value="square" />square
</label>
<label for="decimal">
<input type="radio" id="decimal" name="type" value="decimal" />decimal
</label>
<label for="cjk-decimal">
<input
type="radio"
id="cjk-decimal"
name="type"
value="cjk-decimal" />cjk-decimal
</label>
<label for="decimal-leading-zero">
<input
type="radio"
id="decimal-leading-zero"
name="type"
value="decimal-leading-zero" />decimal-leading-zero
</label>
<label for="lower-roman">
<input
type="radio"
id="lower-roman"
name="type"
value="lower-roman" />lower-roman
</label>
<label for="upper-roman">
<input
type="radio"
id="upper-roman"
name="type"
value="upper-roman" />upper-roman
</label>
<label for="lower-greek">
<input
type="radio"
id="lower-greek"
name="type"
value="lower-greek" />lower-greek
</label>
<label for="lower-alpha">
<input
type="radio"
id="lower-alpha"
name="type"
value="lower-alpha" />lower-alpha, lower-latin
</label>
<label for="upper-alpha">
<input
type="radio"
id="upper-alpha"
name="type"
value="upper-alpha" />upper-alpha, upper-latin
</label>
<label for="arabic-indic">
<input
type="radio"
id="arabic-indic"
name="type"
value="arabic-indic" />arabic-indic
</label>
<label for="armenian">
<input type="radio" id="armenian" name="type" value="armenian" />armenian
</label>
<label for="bengali">
<input type="radio" id="bengali" name="type" value="bengali" />bengali
</label>
<label for="cambodian">
<input type="radio" id="cambodian" name="type" value="cambodian" />cambodian
</label>
<label for="cjk-earthly-branch">
<input
type="radio"
id="cjk-earthly-branch"
name="type"
value="cjk-earthly-branch" />cjk-earthly-branch
</label>
<label for="cjk-heavenly-stem">
<input
type="radio"
id="cjk-heavenly-stem"
name="type"
value="cjk-heavenly-stem" />cjk-heavenly-stem
</label>
<label for="cjk-ideographic">
<input
type="radio"
id="cjk-ideographic"
name="type"
value="cjk-ideographic" />cjk-ideographic
</label>
<label for="devanagari">
<input
type="radio"
id="devanagari"
name="type"
value="devanagari" />devanagari
</label>
<label for="ethiopic-numeric">
<input
type="radio"
id="ethiopic-numeric"
name="type"
value="ethiopic-numeric" />ethiopic-numeric
</label>
<label for="georgian">
<input type="radio" id="georgian" name="type" value="georgian" />georgian
</label>
<label for="gujarati">
<input type="radio" id="gujarati" name="type" value="gujarati" />gujarati
</label>
<label for="gurmukhi">
<input type="radio" id="gurmukhi" name="type" value="gurmukhi" />gurmukhi
</label>
<label for="hebrew">
<input type="radio" id="hebrew" name="type" value="hebrew" />hebrew
</label>
<label for="hiragana">
<input type="radio" id="hiragana" name="type" value="hiragana" />hiragana
</label>
<label for="hiragana-iroha">
<input
type="radio"
id="hiragana-iroha"
name="type"
value="hiragana-iroha" />hiragana-iroha
</label>
<label for="japanese-formal">
<input
type="radio"
id="japanese-formal"
name="type"
value="japanese-formal" />japanese-formal
</label>
<label for="japanese-informal">
<input
type="radio"
id="japanese-informal"
name="type"
value="japanese-informal" />japanese-informal
</label>
<label for="kannada">
<input type="radio" id="kannada" name="type" value="kannada" />kannada
</label>
<label for="katakana">
<input type="radio" id="katakana" name="type" value="katakana" />katakana
</label>
<label for="katakana-iroha">
<input
type="radio"
id="katakana-iroha"
name="type"
value="katakana-iroha" />katakana-iroha
</label>
<label for="khmer">
<input type="radio" id="khmer" name="type" value="khmer" />khmer
</label>
<label for="korean-hangul-formal">
<input
type="radio"
id="korean-hangul-formal"
name="type"
value="korean-hangul-formal" />korean-hangul-formal
</label>
<label for="korean-hanja-formal">
<input
type="radio"
id="korean-hanja-formal"
name="type"
value="korean-hanja-formal" />korean-hanja-formal
</label>
<label for="korean-hanja-informal">
<input
type="radio"
id="korean-hanja-informal"
name="type"
value="korean-hanja-informal" />korean-hanja-informal
</label>
<label for="lao">
<input type="radio" id="lao" name="type" value="lao" />lao
</label>
<label for="lower-armenian">
<input
type="radio"
id="lower-armenian"
name="type"
value="lower-armenian" />lower-armenian
</label>
<label for="malayalam">
<input type="radio" id="malayalam" name="type" value="malayalam" />malayalam
</label>
<label for="mongolian">
<input type="radio" id="mongolian" name="type" value="mongolian" />mongolian
</label>
<label for="myanmar">
<input type="radio" id="myanmar" name="type" value="myanmar" />myanmar
</label>
<label for="oriya">
<input type="radio" id="oriya" name="type" value="oriya" />oriya
</label>
<label for="persian">
<input type="radio" id="persian" name="type" value="persian" />persian
</label>
<label for="simp-chinese-formal">
<input
type="radio"
id="simp-chinese-formal"
name="type"
value="simp-chinese-formal" />simp-chinese-formal
</label>
<label for="simp-chinese-informal">
<input
type="radio"
id="simp-chinese-informal"
name="type"
value="simp-chinese-informal" />simp-chinese-informal
</label>
<label for="tamil">
<input type="radio" id="tamil" name="type" value="tamil" />tamil
</label>
<label for="telugu">
<input type="radio" id="telugu" name="type" value="telugu" />telugu
</label>
<label for="thai">
<input type="radio" id="thai" name="type" value="thai" />thai
</label>
<label for="tibetan">
<input type="radio" id="tibetan" name="type" value="tibetan" />tibetan
</label>
<label for="trad-chinese-formal">
<input
type="radio"
id="trad-chinese-formal"
name="type"
value="trad-chinese-formal" />trad-chinese-formal
</label>
<label for="trad-chinese-informal">
<input
type="radio"
id="trad-chinese-informal"
name="type"
value="trad-chinese-informal" />trad-chinese-informal
</label>
<label for="upper-armenian">
<input
type="radio"
id="upper-armenian"
name="type"
value="upper-armenian" />upper-armenian
</label>
<label for="disclosure-open">
<input
type="radio"
id="disclosure-open"
name="type"
value="disclosure-open" />disclosure-open
</label>
<label for="disclosure-closed">
<input
type="radio"
id="disclosure-closed"
name="type"
value="disclosure-closed" />disclosure-closed
</label>
<label for="-moz-ethiopic-halehame">
<input
type="radio"
id="-moz-ethiopic-halehame"
name="type"
value="-moz-ethiopic-halehame" />-moz-ethiopic-halehame
</label>
<label for="-moz-ethiopic-halehame-am">
<input
type="radio"
id="-moz-ethiopic-halehame-am"
name="type"
value="-moz-ethiopic-halehame-am" />-moz-ethiopic-halehame-am
</label>
<label for="ethiopic-halehame-ti-er">
<input
type="radio"
id="ethiopic-halehame-ti-er"
name="type"
value="ethiopic-halehame-ti-er" />ethiopic-halehame-ti-er
</label>
<label for="ethiopic-halehame-ti-et">
<input
type="radio"
id="ethiopic-halehame-ti-et"
name="type"
value="ethiopic-halehame-ti-et" />ethiopic-halehame-ti-et
</label>
<label for="hangul">
<input type="radio" id="hangul" name="type" value="hangul" />hangul
</label>
<label for="hangul-consonant">
<input
type="radio"
id="hangul-consonant"
name="type"
value="hangul-consonant" />hangul-consonant
</label>
<label for="urdu">
<input type="radio" id="urdu" name="type" value="urdu" />urdu
</label>
<label for="-moz-ethiopic-halehame-ti-er">
<input
type="radio"
id="-moz-ethiopic-halehame-ti-er"
name="type"
value="-moz-ethiopic-halehame-ti-er" />-moz-ethiopic-halehame-ti-er
</label>
<label for="-moz-ethiopic-halehame-ti-et">
<input
type="radio"
id="-moz-ethiopic-halehame-ti-et"
name="type"
value="-moz-ethiopic-halehame-ti-et" />-moz-ethiopic-halehame-ti-et
</label>
<label for="-moz-hangul">
<input
type="radio"
id="-moz-hangul"
name="type"
value="-moz-hangul" />-moz-hangul
</label>
<label for="-moz-hangul-consonant">
<input
type="radio"
id="-moz-hangul-consonant"
name="type"
value="-moz-hangul-consonant" />-moz-hangul-consonant
</label>
<label for="-moz-urdu">
<input type="radio" id="-moz-urdu" name="type" value="-moz-urdu" />-moz-urdu
</label>
</div>
CSS
ol {
font-size: 1.2rem;
}
.container {
column-count: 3;
}
label {
display: block;
}
input {
margin: 0.4rem;
}
JavaScript
const container = document.querySelector(".container");
const list = document.querySelector("ol");
container.addEventListener("change", (event) => {
list.setAttribute("style", `list-style-type: ${event.target.value}`);
});
结果
我们不局限于本页或规范中定义的列表样式类型。@counter-style @规则允许使用任何字母表创建计数器。
规范
| 规范 |
|---|
| CSS 列表与计数器模块第 3 级 # 文本标记 |
| CSS Counter Styles Level 3 # 扩展 CSS2 |
浏览器兼容性
加载中…
另见
list-style简写属性list-style-image属性list-style-position属性::marker伪元素- CSS 列表和计数器模块
- CSS 计数器样式模块