Know this might be a ridiculous question but what is the difference between using the * universal selector, which I know applies to every single element on the page and using just html?
For example:
* {
margin: 0;
padding: 0;
}
and
html {
margin: 0;
padding: 0;
}
Type selectors are the most basic kind of selector. They match to HTML elements by using the element name but without the angled brackets. For example, to apply a style to the h1 tags, h1 is the selector. The universal selector selects every single element in the whole document.
body is an element selector (selects an element body ) while * is a universal selector (selects all elements).
The universal selector is a special type selector and can therefore be namespaced when using @namespace . This is useful when dealing with documents containing multiple namespaces such as HTML with inline SVG or MathML, or XML that mixes multiple vocabularies. ns|* - matches all elements in namespace ns.
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.
*
wildcard is for all elements in page, doesn't matter what tag, classname, id or attribute it have.
html
is only for <html>
element.
* {
color:red;
}
div {
color: green;
}
<p>this is red</p>
<p>this is red</p>
<div>this is red but styling specifically to green</div>
<p>this is red</p>
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