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>

    出现问题:

    解决问题:

  • 相关阅读:
    常见面试题1
    勒索病毒防范方法
    VMware虚拟机打开后不兼容
    win10桌面显示我的电脑设置
    scala集合和Java集合对应转换操作
    scala中使用redis
    爬虫调研
    hadoop命令
    IDEA打jar包
    spark.mllib
  • 原文地址:https://www.cnblogs.com/jason-davis/p/4009740.html
Copyright © 2011-2022 走看看