為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

Why inline css property with !important not override the class property in firefox ?

  • 4 回覆
  • 1 有這個問題
  • 2 次檢視
  • 最近回覆由 cor-el

more options

Why inline css property with !important not override the class property in firefox ?

We try to replicate the same thing in Chrome and there it overrides correctly but in firefox it shows problem

Let me try to clear the scenario

we have a class

.top-container { display: none !important }

and on element we add style

element.style. display = 'block !important;'

but it don't show the element. While in Chrome (OS MAC) it work fine

My System Configuration

OS - MAC

Firefox Version - Firefox 59.0.2.dmg

There is some issue in attaching snapshot. So I put a stackoverflow link where snapshots are present. Please have a look

https://stackoverflow.com/questions/49760154/is-there-anyway-that-inline-css-property-with-important-not-override-the-class

Why inline css property with !important not override the class property in firefox ? We try to replicate the same thing in Chrome and there it overrides correctly but in firefox it shows problem Let me try to clear the scenario we have a class .top-container { display: none !important } and on element we add style element.style. display = 'block !important;' but it don't show the element. While in Chrome (OS MAC) it work fine My System Configuration OS - MAC Firefox Version - Firefox 59.0.2.dmg There is some issue in attaching snapshot. So I put a stackoverflow link where snapshots are present. Please have a look https://stackoverflow.com/questions/49760154/is-there-anyway-that-inline-css-property-with-important-not-override-the-class

所有回覆 (4)

more options

Please always check your code with upload or direct URL link with W3C.org (World Wide Web Consortium) in charge of standards and practices and future development of web pages and web browsers make the rules on code. Mozilla Firefox follows these rules. W3C.org Who make the rules for web code. HTML https://validator.w3.org/ CSS https://jigsaw.w3.org/css-validator/ and https://validator.w3.org/i18n-checker/ and http://mobile.css-validator.org/

more options

Hi , I read those rules that's why I am asking why it behave differently.

Is there any bug in firefox, may be due to long selector ? 

If you need more details to reproduce this bug please let me know

由 abhaygarg12493 於 修改

more options

Hi if you have the page up and running some where please supply the URL and someone will look at all your code that knows more than I. As the error may not be where you think it is. Meta tag it with No robots, no index and we can see it while others will not.

Staying away from Moz work arounds is always the best.

I will forward this question now as it stands.

more options

Any special reason for using the !important flag since that will possibly makes it less easy to override CSS properties?

The Specificity of a class might be higher than an inline rule and you may not be able to override it..