Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between body and * in css

Tags:

css

what is the difference between

body{
  background: #4b4b4b;
}

and

*{
    background: #4b4b4b;
 }

which has higher priority?

like image 797
user544079 Avatar asked May 04 '11 21:05

user544079


People also ask

What is the difference between * and body in HTML?

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 …

Can we use * in CSS?

The CSS Universal SelectorThe universal selector (*) selects all HTML elements on the page.

What is the body in CSS?

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.

What is a body element selector?

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> .


1 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.

like image 164
Mike Samuel Avatar answered Oct 23 '22 09:10

Mike Samuel