what is the difference between
body{
background: #4b4b4b;
}
and
*{
background: #4b4b4b;
}
which has higher priority?
it work same way as you target in body. is there any differences between * and the body ??? Of course there are. The wildcard selector ( * ) selects ALL the elements in your document, including tags like html, body, p, h1, h2, h3, h4, h5, h6, form, input, button, textarea, select, option, legend, fieldset …
The CSS Universal SelectorThe universal selector (*) selects all HTML elements on the page.
Definition and Usage. The <body> tag defines the document's body. The <body> element contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
The element selector is a way to select all the elements with a given tag name in a document, and apply the same styles to each element with the tag name. Note that you should only write the tag name, and not write brackets around the tag name — h1 , not <h1> .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With