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?