I'm trying to use a container div
to house my webpage, and make its background white. 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
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.
The CSS type selector matches elements by node name. 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. And I created this codepen to show how to apply css to achieve your goal.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.