Possible Duplicate:
Is there a shortcut for setting !important on every property in a CSS file?




我有一个独特的问题。在css中,!important会覆盖已经声明的任何元素-但假设我希望所有样式都覆盖所有其他提到的样式表;好吧,通常我会在HTML文件上将重写第二位,如下所示:

<link rel="stylesheet" type="text/css" href="mystyle.css">
<link rel="stylesheet" type="text/css" href="override.css">


但是由于某种原因,这是行不通的。具体来说,我正在做的是添加类以附加基本的CSS样式。像这样:

<div class="no-border-right float-left no-margin-top"></div>


在我的CSS中:

.no-border-right {
    border-right: 0px solid transparent;
}

.float-left {
    float: left;
}

.no-margin-top {
    margin-top: 0;
}


但是,它仍然不是最重要的。我只是将!important添加到每个元素,但是问题是,我已经构造了14gb库。 (我只有在无聊的时候才从事这个工作……嘿:P)所以我想知道如何在每个元素中添加!important。喜欢:

* {
    ...!important;
}


也许还没有...有什么想法吗?

最佳答案

可能新选择器没有比mystyle.css拥有更高的优先级?

CSS/Training/Priority level of selector

CSS: Understanding the selector's priority / specificity

!important会覆盖这些计算,但是如果可能的话,应该避免使用标准方法,从而避免出现骇客行为。

关于html - 如何在CSS文件中的每个元素上添加!important ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13371016/

10-12 01:36
查看更多