序列选择器

来源:互联网 发布:c语言强制转换 编辑:程序博客网 时间:2024/06/01 21:39

序列选择器

语法:

先建造一个表,有序或者无序表。

<body><ul>    <li>No.1</li>    <li>No.2</li>    <li>No.3</li>    <li>No.4</li></ul><!-- 无序表 --><ol>    <li>one</li>    <li>two</li>    <li>three</li>    <li>four</li></ol><!-- 有序表 -->


然后通过语法ul li:first-child{···}选择无序表中的第一个元素;
通过ul li :last-child{···}选择无序表的最后一个元素。同样适用有序表!

  • 注意:此用法只适合选择首尾元素!

代码演示:

<style>    ul li:first-child {        color:red;    }    /*选中第一个元素*/    ul li:last-child {        color:yellow;        font-family: "微软雅黑";    }    /*选中最后一个元素*/    ol li:first-child{        font-size: 30px;    }    ul li:second-child {        color:blue;    }    /*只使用首尾元素,不适用其他的选择,second无用!*/</style>

效果如图所示:
这里写图片描述