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.