zoukankan      html  css  js  c++  java
  • 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选择器!!!

  • 相关阅读:
    动态规划之背包问题
    Python中import导入上一级目录模块及循环import问题的解决
    Anaconda介绍、安装及使用教程
    负载均衡基础知识
    TCP和UDP的区别(转)
    microsoft visual c++ 14.0 is required问题解决办法
    python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool
    解决Anaconda无法更新的问题
    彻底的理解TCP协议的三次握手和四次分手
    android调试工具 adb命令学习
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4623808.html
Copyright © 2011-2022 走看看