I have been looking at the CSS files for many websites like Facebook and Youtube.
In almost all of them I see this code:
* { margin: 0; padding: 0; }
It is odd, as removing that block in chrome web developer tools doesn't affect the layout of the page.
What does this code mean, and when is it used and why?
The asterisk (*) is known as the CSS universal selectors. It can be used to select any and all types of elements in an HTML page. The asterisk can also be followed by a selector while using to select a child object. This selector is useful when we want to select all the elements on the page.
This is a common technique called a CSS reset. Different browsers use different default margins, causing sites to look different by margins. The * means "all elements" (a universal selector), so we are setting all elements to have zero margins, and zero padding, thus making them look the same in all browsers.
In CSS, a class is a group of elements that are the same or similar. You can have as many elements as you want in a class. And each element can be the member of multiple classes. Every class has CSS attributes (like color and font-size) that are specific to that class. CSS classes are similar to a real-life class.
This is a common technique called a CSS reset. Different browsers use different default margins, causing sites to look different by margins. The *
means "all elements" (a universal selector), so we are setting all elements to have zero margins, and zero padding, thus making them look the same in all browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With