[英]How can I override the * selector for CSS to change my body's background colour?
I'm trying to use a container div
to house my webpage, and make its background white.我正在尝试使用容器div
来容纳我的网页,并将其背景设为白色。 However, behind that container I want to make the background black.但是,在那个容器后面,我想让背景变黑。 How can I do this?我怎样才能做到这一点? When I use *, it makes the entire page black, which I do not want.当我使用 * 时,它会使整个页面变黑,这是我不想要的。
<html>
<body>
<p>Hello World</p>
</body>
</html>
To set the background of your entire body simply add the following to your css要设置整个身体的背景,只需将以下内容添加到您的 css 中
html {
background-color: black;
}
body {
background-color: white;
}
Checkout https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors for more information about different kinds CSS selectors and how to use them.查看https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors以获取有关不同类型 CSS 选择器以及如何使用它们的更多信息。
The CSS type selector matches elements by node name. CSS 类型选择器按节点名称匹配元素。 In other words, it selects all elements of the given type within a document.换句话说,它选择文档中给定类型的所有元素。
Syntax句法
element { style properties }
<html>
<body>
<div id="container">
<p>Hello World</p>
</div>
</body>
</html>
You can wrap the content inside the body tag with a container div element as shown above.您可以使用容器 div 元素将内容包装在 body 标签内,如上所示。 And I created this codepen to show how to apply css to achieve your goal.我创建了这个codepen来展示如何应用 css 来实现你的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.