这个 列表 在CSS中,以特定的方式指定内容或项目的列表,即可以有序或无序地组织,这有助于创建一个干净的网页。它可以用来安排大量内容,因为它们灵活且易于管理。列表的默认样式为无边框。该列表可分为两种类型:
列表项标记: 此属性指定项目标记的类型,即无序列表或有序列表。这个 列表样式类型 属性指定列表项元素的列表项标记(例如光盘、字符或自定义计数器样式)的外观。其默认值为光盘。
语法:
list-style-type:value;
可以使用以下值:
- 圆圈
- 十进位,例如:1、2、3等
- 十进制前导零,例如:01,02,03,04等
- 下罗马
- 上罗马
- 较低的α值,如a、b、c等
- 上阿尔法,例如:A、B、C等
- 广场
实例 :本例描述了CSS列表的各种列表样式类型,其中的值设置为平方和较低的alpha。
HTML
<!DOCTYPE html> < html > < head > < style > ul.a { list-style-type: square; } ol.c { list-style-type: lower-alpha; } </ style > </ head > < body > < h2 > GeeksforGeeks </ h2 > < p > Unordered lists </ p > < ul class = "a" > < li >one</ li > < li >two</ li > < li >three</ li > </ ul > < ul class = "b" > < li >one</ li > < li >two</ li > < li >three</ li > </ ul > < p > Ordered Lists </ p > < ol class = "c" > < li >one</ li > < li >two</ li > < li >three</ li > </ ol > < ol class = "d" > < li >one</ li > < li >two</ li > < li >three</ li > </ ol > </ body > </ html > |
输出:
图像作为列表标记: 此属性将图像指定为列表项标记。这个 列表样式图像 属性用于设置要用作列表项标记的图像。其默认值为“无”。
语法:
list-style-image: url;
实例 :本例描述了带有各种列表样式图像的CSS列表,其中的值设置为图像的url。
HTML
<!DOCTYPE html> < html > < head > < title > CSS list-style-image Property </ title > < style > ul { list-style-image: url( } </ style > </ head > < body > < h1 > GeeksforGeeks </ h1 > < p > Unordered lists </ p > < ul > < li >1</ li > < li >2</ li > < li >3</ li > </ ul > </ body > </ html > |
输出:
列出标记位置: 此属性指定列表项标记的位置。这个 列表样式位置 属性用于设置标记相对于列表项的位置。其默认值为“外部”。
有两种类型的位置标记:
- 列表样式位置:外部; 在这种情况下,要点将在列表项之外。列表中每一行的开头都将垂直对齐。
语法:
list-style-position: outside;
实例 :本例描述了CSS列表的各种列表样式位置,其中的值设置为外部。
HTML
<!DOCTYPE html> < html > < head > < style > ul.a { list-style-position: outside; } </ style > </ head > < body > < h2 > GeeksforGeeks </ h2 > < p > Unordered lists </ p > < ul class = "a" > < li >one < br > In this the bullet points will be outside the list item.</ li > < li >two < br > The start of each line of the list will be aligned vertically. </ li > < li >three</ li > </ ul > </ body > </ html > |
输出:
列表样式位置: 在…内 在这篇文章中,要点将在列表中。沿着项目符号点的线将垂直对齐。
语法:
list-style-position: inside;
实例 :本例描述了CSS列表的各种列表样式位置,其中的值设置为inside。
HTML
<!DOCTYPE html> < html > < head > < style > ul.a { list-style-position: inside; } </ style > </ head > < body > < h2 > GeeksforGeeks </ h2 > < p > Unordered lists </ p > < ul class = "a" > < li >one < br > In this the bullet points will be inside the list item.</ li > < li >two < br > The line along with the bullet points will be aligned vertically.. </ li > < li >three</ li > </ ul > </ body > </ html > |
输出:
速记属性 : 此属性允许我们在一个命令中设置所有列表属性。属性的顺序是类型、位置和图像。如果缺少任何属性,将插入默认值。
实例 :本例描述了使用速记属性的CSS列表。
HTML
<!DOCTYPE html> < html > < head > < style > ul.a { list-style: square inside; } </ style > </ head > < body > < h2 > GeeksforGeeks </ h2 > < p > Unordered lists </ p > < ul class = "a" > < li >one</ li > < li >two</ li > < li >three</ li > </ ul > </ body > </ html > |
输出:
样式列表: 列表可以用CSS格式化。可以为列表设置不同的颜色、边框、背景和填充。
实例 :此示例描述了CSS列表,其中各种样式属性应用于元素。
HTML
<!DOCTYPE html> < html > < head > < style > ul.a { list-style: square; background: pink; padding: 20px; } </ style > </ head > < body > < h2 > GeeksforGeeks </ h2 > < p > Unordered lists </ p > < ul class = "a" > < li >one</ li > < li >two</ li > < li >three</ li > </ ul > </ body > </ html > |
输出:
嵌套列表: 列表也可以嵌套。我们有子节来表示节,所以我们需要列表的嵌套。
实例 :此示例描述了在另一个列表中声明列表的CSS列表。
HTML
<!DOCTYPE html> < html > < head ></ head > < body > < h2 > GeeksforGeeks </ h2 > < ul > < li > one < ul > < li >sub one</ li > < li >sub two</ li > </ ul > </ li > < li > two < ul > < li >sub one</ li > < li >sub two</ li > </ ul > </ li > < li > three < ul > < li >sub one</ li > < li >sub two</ li > </ ul > </ li > </ ul > </ body > </ html > |
输出:
支持的浏览器:
- 谷歌Chrome 95.0
- 微软Edge 95.0
- 火狐93.0
- Internet Explorer 11.0
- 歌剧80.0
- Safari 15.0