如何覆盖类背景颜色?尝试 !important
但不起作用,文本仍然是黄色的。
<!DOCTYPE html>
<html>
<head>
<style>
.myclass {
background-color: yellow ;
}
</style>
</head>
<body>
<p class="myclass" background-color="red !important">This is some text in a paragraph.</p>
</body>
</html>
回答1
如果你想使用内联样式(不好),你应该在 html 元素上使用 style
属性,并且以任何方式使用 css 你应该使用冒号 :
而不是 =
来将 value 赋予属性,试试这个片段:
<!DOCTYPE html>
<html>
<head>
<style>
.myclass {
background-color: yellow;
}
</style>
</head>
<body>
<p class="myclass" style="background-color:red !important;">This is some text in a paragraph.</p>
</body>
</html>
回答2
您需要将内联 css 放入 style
属性中,如下所示:
<!DOCTYPE html>
<html>
<head>
<style>
.myclass {
background-color: yellow ;
}
</style>
</head>
<body>
<p class="myclass" style="background-color: red !important;">This is some text in a paragraph.</p>
</body>
</html>
回答3
你需要提到风格。
<p class="myclass" style="background-color:red !important;">This is some text in a paragraph.</p>