简体   繁体   English

如何覆盖 CSS 的 * 选择器以更改正文的背景颜色?

[英]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.

相关问题 如何覆盖导航栏的背景颜色使其与Jumbotron BG颜色相同? - How can I override my navigation bar background colour to be the same as jumbotron BG colour? 如何更改背景色的不透明度? - How can I change the opacity of a background colour? 如何在不使用color属性的情况下更改文本的颜色? (HTML和CSS) - How can I change the colour of my text without using the colour attribute? (HTML & CSS) 我可以在单个CSS选择器中覆盖引导程序的默认设置吗? - Can I override bootstrap's defaults in a single css selector? CSS 使用 :target 选择器更改整个表格行的背景颜色 - CSS Change background colour of an entire table row using :target selector 如何防止SVG图像周围的CSS背景颜色“渗出”? - How can I prevent CSS background-colour “bleed” around my SVG images? 向下滚动时如何更改菜单的背景颜色? - How can I change the background colour of my menu when i scroll down? 如何使用 nth-child inline 更改行的背景颜色? - How can I change a row's background colour with nth-child inline? 当我滚动到其他背景颜色时,如何使用CSS更改徽标的颜色 - How do I use CSS to alter the colour of my logo when I scroll onto a different background colour CSS:在body元素选择器中更改background-image的不透明度 - CSS: Change opacity of background-image within the body element selector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM