CSS
Allen 2021-11-10 13:07:54 4713 0 0 0 0
CSS,笔记,CSS列表CSS列表属性作用如下:设置不同的列表项标记为有序列表设置不同的列表项标记为无序列表设置列表项标记为图像列表在HTML中,有两种类型的HTML列表:无序列表-列表项的标记使用特殊图形(如小黑…

CSS 列表


CSS 列表属性作用如下:

  • 设置不同的列表项标记为有序列表
  • 设置不同的列表项标记为无序列表
  • 设置列表项标记为图像

列表

在 HTML 中,有两种类型的 HTML列表:

  • 无序列表 - 列表项的标记使用特殊图形(如小黑点、小方框等)
  • 有序列表 - 列表项的标记使用数字或字母

使用CSS,可以列出进一步的样式,并可用图像作列表项标记。

不同的列表项标记

list-style-type 属性指定列表项标记的类型是:

ul.a {list-style-type: circle;}
ul.b {list-style-type: square;}

ol.c {list-style-type: upper-roman;}
ol.d {list-style-type: lower-alpha;}

也可以用图像
ul {list-style-image: url('sqpurple.gif');}

一些值是无序列表,以及有些是有序列表。

下列是对 list-style-type 属性的常见属性值的描述:

none:不使用项目符号

disc:实心圆

circle:空心圆

square:实心方块

decimal:阿拉伯数字 

lower-alpha:小写英文字母 

upper-alpha:大写英文字母 

lower-roman:小写罗马数字 

upper-roman:大写罗马数字

利用 list-style-position 可以确定标志出现在列表项内容之外还是内容内部。

如果你想在所有的浏览器放置同样的形象标志,就应使用浏览器兼容性解决方案,方法如下。

ul {
  list-style-type: none;
  padding: 0px;
  margin: 0px;
}
ul li {
  background-image: url(sqpurple.gif);
  background-repeat: no-repeat;
  background-position: 0px 5px;
  padding-left: 14px;
}

解释:
ul :设置列表样式类型为没有列表项标记
设置填充和边距 0px(浏览器兼容性)
ul 中所有 li :设置图像的 URL ,并设置它只显示一次(无重复)
您需要的定位图像位置(左 0px 和上下 5px )
用 padding-left 属性把文本置于列表中

列表 -简写属性

在单个属性中可以指定所有的列表属性。这就是所谓的简写属性。

为列表使用简写属性,列表样式属性设置如下:

ul {
  list-style: square url("sqpurple.gif");
}

如果使用缩写属性值的顺序是:
list-style-type
list-style-position (有关说明,请参见下面的CSS属性表)
list-style-image在简写属性时,如果上述值丢失一个,其余仍在指定的顺序,就没关系。

更多实例

所有不同的列表项标记

这个例子演示了所有不同的 CSS 列表项标记。

    ul.a {list-style-type:circle;} /*圆点空心*/
    ul.b {list-style-type:disc;}  /*圆点实心*/
    ul.c {list-style-type:square;}   /*方块*/
    ol.d {list-style-type:armenian;}  /**/
    ol.e {list-style-type:cjk-ideographic;} /*大写中文数字*/
    ol.f {list-style-type:decimal;}  /*数字*/
    ol.g {list-style-type:decimal-leading-zero;}  /*数字填零*/
    ol.h {list-style-type:georgian;}  /**/
    ol.i {list-style-type:hebrew;}   /**/
    ol.j {list-style-type:hiragana;} /*日文*/
    ol.k {list-style-type:hiragana-iroha;}  /*日文*/
    ol.l {list-style-type:katakana;}  /*日文*/
    ol.m {list-style-type:katagana-iroha;}  /*数字1,2,3*/
    ol.n {list-style-type:lower-alpha;}  /*小写字母abc*/
    ol.o {list-style-type:lower-greek;}  /*希腊字母*/
    ol.p {list-style-type:lower-latin;}  /*小写拉丁字母*/
    ol.q {list-style-type:lower-roman;}  /*小写罗马*/
    ol.r {list-style-type:upper-alpha;}  /*大写字母*/
    ol.s {list-style-type:upper-latin;}  /*大写拉丁*/
    ol.t {list-style-type:upper-roman;}  /*大写罗马*/
    
    ol.u {list-style-type:none;}  /*无序号*/
    ol.v {list-style-type:inherit;}  /**/

所有的CSS列表属性

属性 | 描述

list-style | 简写属性。用于把所有用于列表的属性设置于一个声明中

list-style-image | 将图象设置为列表项标志。

list-style-position | 设置列表中列表项标志的位置。

list-style-type | 设置列表项标志的类型。


参考:https://www.w3cschool.cn/css/css-list.html


Tag: CSS 笔记
我也要发一个   ·   返回首页   ·   返回[CSS]   ·   前一个   ·   下一个
欢迎评论
未登录,
请先 [ 注册 ] or [ 登录 ]
(一分钟即可完成注册!)
返回首页     ·   返回[CSS]   ·   返回顶部