zoukankan      html  css  js  c++  java
  • 关于css里决定样式优先级的权重

    最近学css样式,优先级有点繁琐,简单记录一下。

    css中的优先级规则为:

    1. 有!important的最优先;
    2. 其次权重高的优先;
    3. 权重相同则后定义优先,会覆盖前面的。

    至于权重:

    1. #id 为100;
    2. class类或伪类、属性选择器为10;
    3. 标签选择器为1
    4. 内联样式style= 为1000。

    所以有上图的权重值。

    至于继承,谁在body中更靠近p标签就用谁,若靠近程度一样,则继续用权重比较。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>权重</title>
        <style>
            #box1 .b p{
                color: green;}
            #box1 .b .c p{
                color: red;}
            #lyf p{
                color: yellow;}
            #box2 #box3 p{
                color: darkblue;}
            p{
                color: darkorange !important;}
            
            #box2{
                color: #123;}
            #box1{
                color: #789;}
        </style>
    </head>
    <body>
        <div id="box1"  class="a">
            <div id="box2" class="b">
                <div id="box3" class="c">
                    <p id="lyf" class="d" >刘亦菲</p>
                </div>
            </div>
        </div>
    </body>
    </html>
  • 相关阅读:
    android(eclipse)界面控件以及活动总结(二)
    android(eclipse)新手常见问题总结(一)
    易 忽略 知识 点
    switfmailer 邮件时间错误 处理
    error_log
    $_SERVER['URI']
    apache 服务器配置
    sock
    __autolaod
    delete CDU
  • 原文地址:https://www.cnblogs.com/wangyi0419/p/11632503.html
Copyright © 2011-2022 走看看