What is the difference between * and body in CSS?

Source: Internet
Author: User

What is the difference between a * and body in CSS:
recommendation : As far as possible handwriting code, can effectively improve the learning efficiency and depth.
In introducing them both we should first know what roles these two symbols play in the CSS file. In the CSS file * is a wildcard selector , it can select all the elements in the document, that is, a pass-kill selector. Body is an ordinary type selector , only one element of the body can be selected. And everyone will feel that * and the body selector sometimes function is the same, mainly because the body is the majority of the layout elements of the parent element, if the element's CSS property is inherited, then the effect is exactly the same. For example:

Body {font-size:12px;} * {Font-szie:12px;}

The function of the above two code is exactly the same, because Font-size is the right inheritance. But people still have to understand that their principle is not the same, * The selector is indeed the selection of each element and their font size is set to 12px,body the font is set to 12px through inheritance.
Suggestions:
There is a code at the beginning of many CSS pages:

* {  margin:0;   padding:0}

Because many elements have default padding or margins, such as body, UL, p, and Title element H1-h6. Using the above code makes it easy to clear the margins and padding of all elements, but it can also cause problems. For example:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><styletype= "Text/css">*{margin:0px;padding:0px;}input{Height:40px;}</style></Head><Body><inputtype= "text"name= "MyTest" /></Body></HTML>

The above code may cause text boxes in some browsers to be entered in the upper left corner, not so the browser. It is recommended that you define styles uniformly using the following methods:

body,ul,h1,h2,h3,h4,h5,h6,form,dl,p {   style code }

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=4758

What is the difference between * and body in CSS?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.