zoukankan      html  css  js  c++  java
  • 选择器的使用(nth-child和nth-last-child选择器)

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <style type="text/css">
            li:nth-child(2) {
            background-color:limegreen;
             /*从左开始计数, li:nth-child(2) 就是第2个*/
            }
            li:nth-last-child(1) {
           
            background-color:red;
            /*从last开始计数, li:nth-last-child(1) 就是倒数第一个*/
            }
        </style>
    </head>
    <body>
        <h2>列表A</h2>
        <ul>
            <li>列表项目1</li>
            <li>列表项目2</li>
            <li>列表项目3</li>
            <li>列表项目4</li>
            <li>列表项目5</li>
        </ul>
    </body>
    </html>

    效果如下:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <style type="text/css">
            /*li:nth-child(2) {
            background-color:limegreen;
            从左开始计数, li:nth-child(2) 就是第2个
            }
            li:nth-last-child(1) {
           
            background-color:red;
            从last开始计数, li:nth-last-child(1) 就是倒数第一个
            }*/
             li:nth-child(odd) {
            background-color:limegreen;
            /*所以正数上去的偶数个元素*/
            }
            li:nth-last-child(even) {
           
            background-color:red;
           /*所有倒数上去的奇数个元素*/
            }
        </style>
    </head>
    <body>
        <h2>列表A</h2>
        <ul>
            <li>列表项目1</li>
            <li>列表项目2</li>
            <li>列表项目3</li>
            <li>列表项目4</li>
            <li>列表项目5</li>
        </ul>
    </body>
    </html>

    效果如下:

  • 相关阅读:
    iOS之项目常见文件、UIApplication详解及UIApplicationDelegate的代理方法
    ios关于uibutton内部结构
    ios关于图片拉伸的版本间的几种方法
    uitalbview加载xib详解
    xcode4.2工程Created by名字的修改问题
    工作中常用到的测试分享工具
    IOS 分享 牛人 Demo
    ios输入内容正则表达式的应用
    ios-学习篇-归档
    IOS-网络(GCD)
  • 原文地址:https://www.cnblogs.com/jason-davis/p/4009691.html
Copyright © 2011-2022 走看看