如何使用 css 覆盖所有 类 的背景颜色?

How to override background-color for all classes using css?

我正在使用不允许编辑的 CSS 主题,我需要一种方法来将所有白色 backgroud-color 涂上不那么闪亮的东西。

我是 CSS 的新手,我应该如何使用 CSS 覆盖所有 class 的背景颜色?

这是一个屏幕截图,我正在使用 Primefaces 生成网页内容,因此我无法更改提供的 CSS

A screen shot of what I'm trying to change

我已经知道主题中的每个元素都有自己的 class,但我不知道它们的名字,也不知道这些 class 中的哪一个提供了 background-color对于这些元素,我正在寻找一种在整个页面中重绘白色的简单方法。

来自官方documentation:

Specificity is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied.

还有:

Specificity is based on the matching rules which are composed of CSS selectors of different sorts.

这意味着 CSS 将根据您的浏览器和该浏览器的 CSS Selectors 应用。

而且你还应该看看CSS Selectors哪个有更高的特异性

但是因为您想覆盖 background-color,这意味着要获得更高的 CSS Selector 特异性,我认为您正在寻找的是 !important exception.

再次来自文档:

this declaration overrides any other declarations.

这意味着您要设置 !important 异常的 CSS 的 属性 将被应用,覆盖具有 属性 的其他不同配置.

而且,你必须关心滥用 属性:

Using !important is bad practice and should be avoided because it makes debugging more difficult by breaking the natural cascading in your stylesheets.

我推荐的是:

  • 尝试将 background-color 设置为具有更高特异性的 CSS Selectors

  • 如果你不能修改属性,并且你已经尝试了所有的可能性,那么使用!important例外。

您可以将其粘贴到页面底部的标记之前。

<script>
    document.body.style.backgroundColor = "#883377";
</script>

您可以将 #883377 更改为您想要的任何颜色。