首页 > 其他 > 详细

nth-child()选择器

时间:2020-06-11 22:26:18      阅读:58      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        /* 选中第一个元素*/
        div ul li:first-child{
            font-size: 20px;
            color: red;
        }
        /*选中最后一个元素*/
        div ul li:last-child{
            font-size: 20px;
            color: yellow;
        }
        /*选中指定的元素,数值从1开始。*/
        div ul li:nth-child(3){
            font-size: 20px;
            color: green;
        }
        /*选中所有的元素,括号内必须是n*/
        div ul li:nth-child(n){
            font-size: 30px;
            color: purple;
        }
        /*选中偶数位*/
        div ul li:nth-child(2n){
            font-size: 30px;
            color: pink;
        }
        /*选中奇数位*/
        div ul li:nth-child(2n+1){
            font-size: 30px;
            color:black;
        }
        /*隔一定的位置换色,
        例如:隔2换色,就是3n+1*/
        div ul li:nth-child(3n+1){
            font-size: 30px;
            color: skyblue;
        }
    </style>
</head>
<body>
    <div>
        <ul>
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
    </div>
</body>
</html>

 

nth-child()选择器

原文:https://www.cnblogs.com/Rooney10/p/13096414.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!