是否可以使一个重要的属性值从CSS选择器不重要? [英] Is possible to make an important property value from CSS selector a non important one?
问题描述
有可能使CSS选择器的重要属性值不重要吗?
Is possible to make an important property value from CSS selector a non important one?
例如: Bootstrap 3定义 .hide
class as:
For example: Bootstrap 3 defines .hide
class as:
.hide { display: none !important; }
是否可以删除重要值而不修改BS3源代码?
Is possible to remove the important value without modifying the BS3 source code?
思考somethingl iike
Thinking at somethingl iike
.hide { display: none !remove-important; }
请注意,我想保持相同的值!我不想将 block!important
设置为 .hide
类,因为那将不正确...
Note that I want to keep the same value! I don't want to set block !important
to .hide
class because that would not be correct...
我已经添加了一个新类 .hide-non-important
,并在需要的地方使用:
I already added a new class .hide-non-important
and used it where it was needed:
.hide-not-important { display: none; }
...但问题是:有什么替代方法吗?
...but the question is: is there any alternative to this?
推荐答案
您不需要编辑原始源代码。只需创建一个样式表并将它放在Bootstrap样式表后面,并将其添加到它:
You don't need to edit the original source code. Just create a stylesheet and place it after the Bootstrap stylesheets and add this to it:
.hide { display: block !important; }
现在,说了这个,我会非常小心这样做。你不知道你的网站上有多少元素应用了这个类,你几乎肯定会得到意想不到的结果。
Now, having said this, I would be very careful about doing this. You don't know how many elements across your site have applied this class, and you will almost certainly get unanticipated results.
显然有一个原因,这个类已被应用,我建议:
There is obviously a reason that this class has been applied, I would suggest either:
-
不要这样做
don't do this
向元素添加一些其他类,并为其添加样式。调整您的标记(如果需要,请使用js应用类):
add some other class to the element and add styles to that. Adjust your markup (or use js to apply the class if need be) to something like:
<div class="hide custom-hide-reset"></div>
然后将此样式添加到您创建的样式表:
Then add this style to the stylesheet you've created:
.custom-hide-reset { display: none; }
这篇关于是否可以使一个重要的属性值从CSS选择器不重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!