CSS选择器的使用

<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8">
        <title>常用选择器</title>
        <style>/*内部样式*/

        /* 1.元素选择器,又称为类型选择器 */
           h1{
                color:royalblue;
                font-size: 25px;
                font-family: 华文行楷,宋体,微软雅黑;
           }

        /*  2.类选择器,以“.”开头,通过“class”属性引用 */
           .Class1{
               color:red;
               font-size: 23px;
               font-family: 隶书;
           }
           .Class2{
               color:red;
               font-size: 23px;
               font-family: 幼圆;
           }

        /*  3.ID选择器,以“#”开头,通过“id”属性引用 */

           #id1{
               color: seagreen;
               font-size: 30px;
               font-family:Arial, Helvetica, sans-serif;
           }
        /*  4.后代选择器 */
           h4 p span{
               color:skyblue;
               font-size: 20;
               font-family: fantasy;
           }
        /*  5.组合选择器 */
           h5,h6{
               color:springgreen;
               font-size: 15px;
               font-family: cursive;
           }
        /*  6.父子选择器,父选择器包含子选择器,并且样式只能作用在子选择器
              上,而不能作用到父选择器上 */
           p>span{
               color: tomato;
               font-size: large;
               font-family: 微软雅黑;
           }
        /*  7.相邻选择器,选择紧接在某一个元素后的元素,并且二者
              有相同的父元素 */
           h2+h4{
                color: thistle;
                font-size: larger;
           }
        /*  8.属性选择器,对带有指定属性的HTML元素进行样式设置 */
           h1[align]{
               color:red;
           }
        /*  9.通用选择器,以“*”开头,即所有标记都使用该样式 */
           /* 
           *{
               color:thistle;
           } 
           */

        </style>
    </head>
    <body>
        <h1>一号标题</h1>
        <!--内嵌样式-->
        <h2 style="font-family: 仿宋; font-size: 20px; color: salmon;">二号标题</h2>
        <!--如果在两个类选择器中都同一个样式属性进行了样式定义,则后定义的样式起作用-->
        <h3 class="Class1 Class2">三号标题(类选择器)</h2>
        <h3 class="Class1">四号标题</h3>
        <h4 id="id1">The fourth title</h4>
        <span id="id1">The fourth tilte</span>
        <h4>
            <p>
                <span>The fifth title</span>
                <p>The fifth title</p>
            </p>
            <span>The fifth title</span>
        </h4>

        <h5>The sixth title</h5>
        <h6>The seventh title</h6>

        <p>
            <span>父选择器二号子</span>
            <p>父选择器一号子<span>Over</span></p>
        </p>

        <h2>
            <p>相邻选择器一号</p>
            <h2>相邻二号</h1>
            <h4>相邻三号</h4>
            <h4>相邻四号</h4>
        </h1>

        <h1 align="center">属性选择器</h1>


    </body>
</html>

运行结果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值