What is difference between * and body used in style tag of html? If any examples are there, will help me for understanding. Thank you..
-
4Possible duplicate of [difference between body and \* in css](https://stackoverflow.com/questions/5890342/difference-between-body-and-in-css) – codesayan Aug 10 '17 at 04:29
2 Answers
The body selector has higher priority, but the * selector applies more broadly, so in <body>foo<p>bar</p></body>
the body selector will determine the background of the text foo, but the * selector will determine the background of the <p>
element.
Note, also that many browsers create an element around the <body>
that includes its margins and scrollbars, so the * selector may also determine the color of that region.
answered May 4 '11 at 22:01
Mike Samuel

- 83
- 1
- 10
body {
color: black;
background-color: white;
}
This rule applies the colors to the body element. All descendants of the body element inherit its color.
Similarly to how the background of html is generated to the viewport automatically, the background of the body will be generate to html automatically, until and unless you set a background for html as well. Because of this, if you only need one background (in usual circumstances), whether you use the first rule or the second rule won't make any real difference
Asterisk (*) is a wildcard and it means all elements.
* {
color: black;
background-color: white;
}
This rule applies the colors to every element, so neither of the two properties is tacitly inherited. But you can easily override this rule with anything else, as * has exactly no significance in selector specificity.

- 187
- 1
- 14