如何用CSS覆盖HTML body bgcolor属性?

时间:2022-11-12 11:20:11

I'm writing an external user stylesheet for an old HTML page that specifies the background colour in the body tag: <BODY BGCOLOR="#808000"> (note: I can't edit the HTML).

我正在为旧的HTML页面编写外部用户样式表,该页面指定了body标签中的背景颜色:(注意:我无法编辑HTML)。

I've tried writing the obvious stylesheet:

我试过编写明显的样式表:

body {
  background-color: #ffffff !important;
}

but it has no effect: the original colour remains.

但它没有效果:原始颜色仍然存在。

Can it be done with CSS? If so, how?

可以用CSS完成吗?如果是这样,怎么样?

2 个解决方案

#1


It works fine here (I tested it). Are you sure the stylesheet is being imported properly?

它在这里工作正常(我测试过)。你确定样式表正在正确导入吗?

#2


FIX: I've checked it in my place it works

FIX:我在我的位置检查了它的工作原理

body
{
    background-color: white;
}

You can also do

你也可以这样做

<body style="background-color:red"></body>

#1


It works fine here (I tested it). Are you sure the stylesheet is being imported properly?

它在这里工作正常(我测试过)。你确定样式表正在正确导入吗?

#2


FIX: I've checked it in my place it works

FIX:我在我的位置检查了它的工作原理

body
{
    background-color: white;
}

You can also do

你也可以这样做

<body style="background-color:red"></body>