css优先级学习总结

!important>内联>id>class(类)、属性、伪类>标签、伪元素>*通配符>继承

!important :
<style>
	//id格式为#name
	#one{
		color:red;
		}
	//class格式为.name	
	.two{
		color:blue !important;
		}
</style>
//最终效果是文字颜色为蓝色
<div id="one" class="two">我是div</div>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>07-CSS属性的优先级_03</title>
    <style>
        .ziti{
            color: #0f0;
            font-size: 20px;
        }
        #box{
            color: #f00;
        }
        *{
            /* color: #ff0 !important; */
            font-size: 50px;
        }
        //属性:中括号加属性名称
        [xx]{
            color: #0f0;
        }
        [yy*="y"]{
            color: rgb(169, 33, 76);
        }
        p{
            color: aquamarine;
        }
        //动态伪类:悬停、长按active、浏览过visited、未点击link
        a:hover{
            color: blue;
        }
        //结构伪类:父标签下的第n个标签且是span标签
        span:nth-child(9){
            color: aqua;
        }
        //结构伪类:父标签下的第n个span标签
        span:nth-of-type(2){
            color: #f333f3;
        }
        //伪元素:before、after
        li::first-letter{
            color: #f00;
        }
        li{
            list-style: none;
        } 
        ol{
            padding: 0px;
            margin: 0px;
        }
        ol::first-line{
            color: #f333f3;
        }
        //a标签中,以aaaa开头的href属性+动态伪类(悬停)+伪元素
        a[href^="aaaa"]:hover::after{
            content: "["attr(href)"]"; //content追加内容,格式为content:"",
            							//attr(href)表示读取href的值,
        }
        article::after{
            content: "after";
        }
        article::before{
            content: "before";
        }
    </style>
</head>
<body >
    <div style="color: #000;">内联选择器</div>
    <div class="ziti">class(类选择器)</div>
    <span xx="xx">属性选择器</span>
    <div id="box">id选择器</div>
    <span yy="yy">属性选择器</span>
    <p>标签选择器</p>
    <a href="https://baidu.com" target="_blank">动态伪类选择器</a><br>
    <span>结构伪类选择器</span>
    <div>
        <span>结构伪类选择器</span><br>
        <span>结构伪类选择器</span>
    </div>
    <li>伪元素与标签优先级相同</li>
    <ol>伪元素与标签优先级相同</ol>
    <a href="aaaa://www.taobao.com">淘宝</a>
    <article>伪元素(..前..后)</article>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值