What does * refer to?

I am considering replacing

body, label, p, div, input{ padding: 0px; margin: 0px; } 

with

 * { margin: 0; padding: 0; } 

Is * catch everything? What elements does it apply to?

I am passing some CSS from here , and I need it to display correctly, but I have never used * before.

+4
source share
3 answers

It applies to every element in the document , from the root <html> element to any other existing element. Also note that this selector is not specific, so any declaration for the same element and property will override it.

+5
source

* means "all elements" - it is not recommended to use it at all, because if you have deep levels of nested elements, it will correspond to each element in this chain and the cascade is much more than necessary.

+3
source

Like other answers, this applies to all elements that are descendants of the selector that you use in conjunction with.

One use case that is useful for * (and not for hacking CSS to work with IE) has a direct selector:

 body div.content > * { ... } 

In this example, all direct children of the div.content will be selected, regardless of the type of tag, and only direct children.

+1
source

Source: https://habr.com/ru/post/1483860/


All Articles