Ddoouummbbiiaa
Ddoouummbbiiaa

Reputation: 27

Background Color and Tags

I have a simple question for you that I am not sure about. If a p tag has no CSS-code but the body tag has following code:

 body {
 background-color: white;
 color: red;
 font-family: "Calibri";
}

... I know that the p tag gets the color red and the font Calibri, but does the p tag get the background color

background-color: white

...or does it get no background-color?

Thanks!

Upvotes: 1

Views: 424

Answers (1)

Jakob
Jakob

Reputation: 1905

The <p> tag gets the background-color, if no background-color is set for the <p> tag.

For example:

HTML:

<p>test text</p>

CSS:

body {
background-color: red;
font-family: "Calibri";
}

Now you have background-color: red; and no other background-color is set for the <p> tag so the <p> tag gets background-color: red;.

enter image description here

But if you set a background-color to the <p> tag, the background-color of the <p> tag is preferred.

HTML:

<p style="background-color: green;">test text</p>

CSS:

body {
background-color: red;
font-family: "Calibri";
}

So the result is:

enter image description here

Upvotes: 1

Related Questions