Get the App
SLTechnology News&Howtos  ›  Development  › 

Why do you set margin and padding values to zero in CSS

Shulou Source: shulou.com Published: 2022-06-01 12:47:59 09月30日 Update

This article mainly introduces the CSS why to set the margin and padding value to zero related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will gain something after reading this CSS why you set the margin and padding value to zero, let's take a look.

Many careful students should have noticed that when we first started writing CSS files, we would set the values of margin and padding to zero, but do you know why?

* {margin: 0; padding: 0;}

Generally speaking, when we style a web page, we need to add the above code at the beginning. Because HTML elements or tags have default styles and margins, if you don't want to be affected, you need to empty its own style first. In addition, there is the problem of browser compatibility. The margin of different browsers is different. For example, the body tag defaults to 8 pixels of margin. In order to meet this kind of demand, you need to set margin and padding in advance, so that our custom CSS style will not deviate. Another advantage of setting margin to 0 is that it is convenient to center.

This is the end of the article on "Why margin and padding values are set to zero in CSS". Thank you for reading! I believe you all have a certain understanding of the knowledge of "why margin and padding are set to zero in CSS". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Style knowledge content that is tags browsers articles browsing different same careful code value deviation pixels elements students benefits beginning simple operation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information vpn NVidia Redmi