Does it really work to specify a margin and a padding to 0 initially?

1

I have seen that it is very common that as soon as you start the css, many files start with:

*{
    margin: 0;
    padding: 0;
}

Used in theory so that all elements have no padding or margin. Does this really work? Because I have had many times to modify some element. I do not know if it's because I use libraries like Bootstrap, which makes the elements have a series of properties.

    
asked by Pelayo 26.04.2018 в 09:28
source

2 answers

2

Running works, it has been a way to reset the padding and margin from a long time . (Although I have found older sources)

However, there are reasons not to use it, the author of the same blog regretted mere months after his decision.

The problem? The performance of the page decreases, this response from stackoverflow gives more information about why, but the reason is simple: The star element applies to all elements of the DOM, and certain web pages can have hundreds of them.

Also remember that the class / property applied to the element is the last specified in the css, so it will not work if another margin or spacing is declared after the initial declaration.

    
answered by 26.04.2018 / 09:48
source
1

Of course it works, but if you add bootstrap or any other css you will surely add margins to the elements that are considered.

On performance, tests have been done with "extreme" amounts of code and selectors like * {...} and the difference was of the order of milliseconds , the engines are already highly optimized and the load of resetting with * is negligible in css. Another thing would be to use in JS / Jquery, there if that would drag the performance considerably.

    
answered by 26.04.2018 в 10:04