前端之样式列表


列表大体上和其他文本一样

List列表

列表的默认样式

ul , ol ,dl 元素设置margin的顶部和底部: 16px(1rem);
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
当我将根元素的字体大小改为10px时,
在这里插入图片描述
所以,list列表的margin-top和margin-bottom都是1rem。

无论根元素的字体大小变没变,ul 和 ol的 padding-left都是 40px,但是
li 默认是没有设置间距的。;
dl的是零,但是dd 的 padding-left是40px;

处理列表间距

<style>
html {
    /* 设置字体 */
    font-size: 10px;
}

ul,
ol,
dl {
    /* 字体大小 */
}

li,
dd {
    /* 行高 */
}

dt {
    /* 粗体 */
}
</style>

列表特定样式

ul 和 ol列表:

  1. list-style-type :设置用于列表的项目符号的类型,例如无序列表的方形圆形项目符号,或有序列表的数字,字母或罗马数字。
  2. list-style-position :设置在每个项目开始之前,项目符号是出现在列表项内,还是出现在其外。
  3. list-style-image :允许您为项目符号使用自定义图片,而不是简单的方形或圆形。

开始前:

<style>
html {
    /* 设置字体 */
    font-family: '宋体', '隶书';
    font-size: 10px;
}

h1 {
    font-size: 3rem;
}

h2 {
    font-size: 2rem;
}

ul,
ol,
dl {
    /* 字体大小 */
    font-size: 1.5rem;
}

li,
dd {
    /* 行高 */
    line-height: 1.5;
}


/* dt {
    粗体
    font-weight: bold;
} */
</style>

符号样式 list-style-type

<style>
/* 有序列表 */

ol {
    list-style-type: upper-alpha;
}
</style>

在这里插入图片描述

项目符号位置 list-style-position

默认是 list-style-position: outside;
在这里插入图片描述
修改成

<style>
/* 有序列表 */

ol {
    list-style-type: upper-alpha;
    list-style-position: inside;
}
</style>

在这里插入图片描述

使用自定义的项目符号图片 list-style-image

支持 png,svg

<style>
/* 有序列表 */

ol {
    list-style-type: upper-alpha;
    list-style-position: inside;
    list-style-image: url('../images/little.png');
}
</style>

在这里插入图片描述

<style>
/* 有序列表 */

ol {
    list-style-type: upper-alpha;
    list-style-position: inside;
    list-style-image: url('../images/little2.svg');
}
</style>

在这里插入图片描述

list-style 速记

<style>
ul {
  list-style-type: square;
  list-style-image: url(example.png);
  list-style-position: inside;
}
/* 等价于
ul {
  list-style: square url(example.png) inside;
}
 */
</style>

有序列表计数 start

<style>

/* 有序列表 */

ol {
    list-style-type: upper-alpha;
    list-style-position: outside;
}
</style>
    <ol start="0">
        <li>斗罗大陆</li>
        <li>武动乾坤</li>
        <li>绝世武神</li>
    </ol>

在这里插入图片描述

倒序

    <ol start="0" reversed>
        <li>斗罗大陆</li>
        <li>武动乾坤</li>
        <li>绝世武神</li>
    </ol>

在这里插入图片描述

value 指定数值

value 属性允许设置列表项指定数值,

<style>

/* 有序列表 */

ol {
    list-style-position: outside;
}
</style>
    <ol>
        <li>斗罗大陆</li>
        <li>武动乾坤</li>
        <li>……</li>
        <li value="100">绝世武神</lival>
    </ol>

在这里插入图片描述
牛刀小试——列表
下一节: 前端之样式化链接、web字体

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值