html中!important属性的实际用法

2021-08-08  本文已影响0人  LRachel

什么是!important

!important是一个修饰符,语法是选择器{属性:属性值 !important}。作用是更改默认的CSS样式优先级。

示例

注意中间要有空格,不能有分号

实际用法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box1 { color: green; }
        #d1 { color: red; }
        p { color: orange !important; }
    </style>
</head>
<body>
          <p id="d1" class="box1">文字颜色</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box1 { color: green !important; }
        #d1 { color: red !important; }
        p { color: orange !important; }
    </style>
</head>
<body>
          <p id="d1" class="box1">文字颜色</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box1 { color: green !important; }
        p { color: orange;}
    </style>
</head>
<body>
     <div class="box1">
          <p>文字颜色</p>
     </div>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读