What is the difference between * and body in CSS and CSS body?

Source: Internet
Author: User

What is the difference between * and body in CSS and CSS body?

What is the difference between * and body in CSS:
Suggestion: writing code as much as possible can effectively improve learning efficiency and depth.
First, we should know the roles that these two symbols play in the CSS file. In a CSS file, * is a wildcard selector. You can select all elements in the document, that is, a killer selector. Body is a common type selector. Only the body element can be selected. Everyone will feel that * and the body selector sometimes play the same role, mainly because the body is the parent element of the vast majority of layout elements. If the CSS attributes of the elements are inherited, the results are indeed the same. For example:

body{font-size:12px;}*{font-szie:12px;}

The functions of the above two codes are exactly the same, because font-size is right-inherited. But you still need to understand that their principles are different. * The selector selects every element and sets their font size to 12px, the body is inherited to set the font to 12px.
Suggestion:
There is such a code at the beginning of many CSS pages:

*{  margin:0;  padding:0}

Because many elements have default padding or padding, such as body, ul, p, and title element h1-h6. With the above code, you can easily clear the outer and inner margins of all elements, but it also causes problems. For example:

<! DOCTYPE html> 

The above code may cause text input in Some browsers to be displayed in the upper left corner, not all in the browser. We recommend that you use the following method to define a uniform style:

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.

Related Article

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.