• css笔记08:id选择器之父子选择器


    1.父子选择器

    (1)01.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>选择器</title>
    <link rel="stylesheet" href="my.css"  type="text/css"/>
    </head>
    
    
    <body>
    你好,北京!
       <span class="style1">新闻1</span>
       <span class="style1">新闻2</span>
       <span class="style1">新闻3</span>
       <span class="style1">新闻4</span>
       <span class="style1">新闻5</span>
       <!--父子选择器使用-->
       <span id="style2">这是一则<span>非常重要</span>的新闻</span><br />
       <span id="style2">这是一则<span>非常<span>重要</span></span>的新闻</span><br />
       
       <a href="#">goto sohu</a><br />
       <a href="#">goto sina</a><br />
    </body>
    </html>

    (2)my.css

    @charset "utf-8";
    /* CSS Document */
    
    /*html的选择器*/
    body {
        color:orange;
    }
    
    a:link {
        color:black;
        text-decoration:none;
    }
    
    a:hover {
        text-decoration:underline;
    }
    
    a:visited {
        color:red;
    }
    
    
    
    /*.style1 就是类选择器*/
    .style1 {
        font-weight:bold;
        font-size:20px;
        background-color:pink;
        color:black;
    }
    
    
    /*#style2就是id选择器*/
    
    #style2 {
        font-size:30px;
        background-color:silver;
        color:black;
    }
    
    /*#style2 span 就是父子选择器, #style2是父,span是子*/
    #style2 span {
        font-style:italic;
        color:red;
    }
    
    /*#style2 span 就是父子选择器, #style2是父,span是子,也包含层次关系*/
    #style2 span span{
        font-size:50px;
    }

    效果图:

    总结:这里子选择器的标签是必须存在,就是<span>不能改成别的不存在的标记;这里#style2 span也包含层次关系,比如也可以写成#style2 span span

    这样三层以上 很少使用。

                父子选择器使用于id选择器和class选择器!!!

  • 相关阅读:
    【java多线程】队列系统之说说队列Queue
    【传输协议】什么是CA证书
    5.1 javassist基本使用
    第四章 dubbo内核之aop源码解析
    第三章 dubbo内核之ioc源码解析
    2.2 dubbo-spi源码解析
    2.1 jdk-spi的实现原理
    第一章 第一个dubbo项目
    第零章 dubbo源码解析目录
    macOS Sierra10.12.5 显示允许任何来源
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4623808.html
Copyright © 2020-2023  润新知