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

    <!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">
            /*h2:nth-child(odd) {
            background-color:yellow;
            }
            h2:nth-child(even) {
            background-color:limegreen;
            }*/
           /*当父元素是列表时,因为列表中可能有列表项目一种子元素,所以不会有问题,而当父元素是<div>时,因为div中包含多种子元素,所以会出现问题。*/
            h2:nth-of-type(odd) {
            background-color:red;
            }
            h2:nth-of-type(even) {
            background-color:skyblue;
            }
        </style>
    </head>
    <body>
        <div>
            <h2>文章标题A</h2>
            <p>文章正文。</p>
            <h2>文章标题B</h2>
            <p>文章正文。</p>
            <h2>文章标题C</h2>
            <p>文章正文。</p>
            <h2>文章标题D</h2>
            <p>文章正文。</p>
        </div>
    </body>
    </html>

    出现问题:

    解决问题:

  • 相关阅读:
    c函数调用过程
    查找匹配行及前后5行
    指向类成员函数的指针
    C++箴言:理解typename的两个含义
    不定参数
    定时器
    unix编译
    sed
    大脑皮层的梦工厂
    静态链接库顺序问题
  • 原文地址:https://www.cnblogs.com/jason-davis/p/4009740.html
Copyright © 2011-2022 走看看