有趣的css —— li 标签的样式操作(含自定义)

最近发现了一个关于html中 li 标签比较有趣的知识,用起来也是嘎嘎香。

1. 常规

日常开发中,避免不了会用到列表,一般我们会将前面的小点去掉,但是除了去掉,我们还可以有更多的选择,在使用li标签的时候,为 list-style-type:加上以下值,会有比较好的效果哦:

disc 实心圆
square 方块
circle  空心圆
decimal 数字
lower-latin小写字母

上css代码:

 li:nth-child(1) {
      list-style-type: disc;
    }
    li:nth-child(2) {
      list-style-type: square;
    }
    li:nth-child(3) {
      list-style-type: circle;
    }
    li:nth-child(4) {
      list-style-type: decimal;
    }
    li:nth-child(5) {
      list-style-type: lower-latin;
    }

效果演示:

 2. 自定义

除了以上常见的一些样式,我们还可以通过 ::marker 伪元素进行自定义样式,达到自己想要的效果

css代码展示:

  li:nth-child(1)::marker {
      content: '♥';
      color: red;
    }
    li:nth-child(2)::marker {
      content: '√';
      color: green;
    }
    li:nth-child(3)::marker {
      content: '卍';
      color: pink;
    }
    li:nth-child(4)::marker {
      content: '④';
      color: blue;
    }
    li:nth-child(5)::marker {
      content: '♪';
      color: orange;
    }

效果演示:

当然除了放自定义符号,我们还可以放图片 

代码:

 li:nth-child(1)::marker {
      content: url(https://s1.ax1x.com/2023/04/13/ppj04e0.png);
    }
 li:nth-child(2)::marker {
      content: url(https://s1.ax1x.com/2023/04/13/ppj0xw6.png);
    }
 li:nth-child(3)::marker {
      content: url(https://s1.ax1x.com/2023/04/13/ppjBpFO.png);
    }

效果:

 去更远的地方,见更亮的光!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值