关闭 CSS 属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11939519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 04:47:31  来源:igfitidea点击:

Turn off CSS property

cssoverriding

提问by user1582524

Lets say I have a plugin's CSS which loads later as my style.css

假设我有一个插件的 CSS,它稍后作为我的 style.css 加载

/*style.css*/
.something {
position:absolute;
left: 0px !important;                       
}

/*plugin's CSS*/
.something {
position:absolute;
left: -50px;                       
} 

/now it has 0px but i want no left value at all/

/现在它有 0px 但我根本不想要左值/

i know i can set !important so that property wont be overriden, but is there any solution to turn "left" off as Chrome DevTools uncheck a property?

我知道我可以设置 !important 以便属性不会被覆盖,但是当 Chrome DevTools 取消选中属性时,是否有任何解决方案可以关闭“左”?

采纳答案by Gravitate

As far as I am aware (someone please feel free to correct me) there is no way to directly "turn off" a CSS property like in the Chrome DevTools.

据我所知(有人请随时纠正我)无法像 Chrome DevTools 那样直接“关闭”CSS 属性。

The closest you can get it to reset the property to its default. In your example, it would be "left:auto;"

最接近您可以将其重置为默认值的方法。在您的示例中,它将是“left:auto;”

P.S. You may wish to adjust your tags to get more views and hopefully answers.

PS 你可能希望调整你的标签以获得更多的观点和希望的答案。

回答by Software Guy

You should use the "auto" value for left:

您应该使用左侧的“自动”值:

.something
{
    position:absolute;
    left:auto !important;
}

"auto" will reset to the default (that is set by browsers for that style)

“自动”将重置为默认值(浏览器为该样式设置)

more info here: http://www.w3schools.com/cssref/pr_pos_left.asp

更多信息在这里:http: //www.w3schools.com/cssref/pr_pos_left.asp

回答by Eric J.

Specificity is the key to selecting the CSS attribute that you really want. Leverage the specific structure of the HTML in the plugin vs. non-plugin case so that specificity rules select the CSS you desire when plugin rules should apply.

特异性是选择您真正想要的 CSS 属性的关键。在插件与非插件的情况下利用 HTML 的特定结构,以便特定规则在应应用插件规则时选择您想要的 CSS。

There's a great overview of specificity here:

这里有一个很好的特异性概述:

enter image description here

在此处输入图片说明

Source: http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html

来源:http: //www.stuffandnonsense.co.uk/archives/css_specificity_wars.html

One thought that comes to mind is to use an additional class, plugin, along with an appropriate selector.

想到的一个想法是使用额外的类plugin以及适当的选择器。

回答by Hazem Salama

If you are trying to override it then you can play with CSS Specificity Rules

如果您试图覆盖它,那么您可以使用CSS 特异性规则