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>
  • 相关阅读:
    topcoder srm 320 div1
    topcoder srm 325 div1
    topcoder srm 330 div1
    topcoder srm 335 div1
    topcoder srm 340 div1
    topcoder srm 300 div1
    topcoder srm 305 div1
    topcoder srm 310 div1
    topcoder srm 315 div1
    如何统计iOS产品不同渠道的下载量?
  • 原文地址:https://www.cnblogs.com/vic-tory/p/13944269.html
Copyright © 2011-2022 走看看