zoukankan      html  css  js  c++  java
  • HTML+CSS系列:CSS选择器(标签、ID、类、通配符、后代、子元素、并集、伪类)

    一.标签选择器

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            h1 {
                color: red;
            }
            h2{
                color: green;
            }
        </style>
    </head>
    
    <body>
        <h1>Hello World!</h1>
        <h1>Hello World!</h1>
        <h2>Hello !</h2>
        <h2>Hello !</h2>
    </body>
    
    </html>

    二.类选择器

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .box {
                color: green;
            }
    
            .box1 {
                font-size: 26px;
            }
        </style>
    </head>
    
    <body>
        <div class="box box1">Hello World!</div>
        <span class="box">Hello World!</span>
    </body>
    
    </html>

    三.ID选择器

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
    #box{
        color: green;
    }
        </style>
    </head>
    <body>
        <div id="box">Hello World!</div>
    </body>
    </html>

    四.通配符选择器

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            *{
                margin: 0;
                padding: 0;
                color: red;
            }
        </style>
    </head>
    <body>
        <div>Hello World</div>
    </body>
    </html>

    五.后代选择器

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            ul li {
                color: red;
            }
    
            ul li a {
                color: green;
            }
    
            .nav li {
                color: yellow;
            }
        </style>
    </head>
    
    <body>
        <ul>
            <li>ul li</li>
            <li>ul li</li>
            <li>ul li</li>
            <li>ul li</li>
            <li>ul li <a href="">a</a></li>
        </ul>
    
        <ol>
            <li>ol li</li>
            <li>ol li</li>
            <li>ol li</li>
            <li>ol li</li>
            <li>ol li</li>
        </ol>
    
        <ul class="nav">
            <li>nav li </li>
            <li>nav li </li>
            <li>nav li </li>
            <li>nav li </li>
            <li>nav li </li>
        </ul>
    </body>
    
    </html>

    六.子元素选择器

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .nav>a {
                color: red;
            }
        </style>
    </head>
    
    <body>
        <div class="nav">
            <a href="#">Hello World</a>
            <p>
                <a href="#">Hello World</a>
            </p>
        </div>
    </body>
    
    </html>
  • 相关阅读:
    PlayerPrefs存储Vector3等结构数据
    Kafka集群部署及測试
    火云开发课堂
    Thinking in Java:容器深入研究
    求int型数据在内存中存储时1的个数
    JAVA 几种多线程的简单实例 Thread Runnable
    Android利用Intent与其它应用交互
    kernel
    Azure DocumentDB 正式发布
    在公有云平台体验开源方案的自动部署
  • 原文地址:https://www.cnblogs.com/vic-tory/p/13944269.html
Copyright © 2011-2022 走看看