博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

!important强制此css最强,其它被覆盖

Posted on 2018-09-10 22:52  alex_hrg  阅读(4378)  评论(0编辑  收藏  举报

有时我们引用别人写的插件不知道某个样式在哪儿,或者想要覆盖其它样式,就要用到 !importan;

例如以下是引用boostrap,默认bootstrap都是圆边框,我们不想用,例子中同一样式也出现多个importan,则写在最下面的生效。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .no-radius{
            border-radius: 0 !important;
        }
        .radius-8{
            border-radius: 8px !important;
        }
    </style>
    <link rel="stylesheet" href="../bootstrap-3.3.7-dist/css/bootstrap.css" />
</head>
<body style="background: blue;">

    <button type="button" class="btn btn-default navbar-btn  radius-8 no-radius">Sign in</button>

<script src="../jquery-3.3.1.js"></script>
<script src="../bootstrap-3.3.7-dist/js/bootstrap.js"></script>
</body>
</html>