CSS3 and html5 the meaning of * special character [duplicate] - css

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
css: the meaning of * mark
What does the symbol * mean in CSS3. As used in a code;
*{
margin: 0;
padding:0;
}

this refers to all the elements and this particular code will make all the element's margin and padding as 0

It's basically a reset style. To cancel out differences in user agent/browser styles.

* is a general and CSS wildcard, the selector you show above selects all elements in a HTML document. It is commonly used in reset stylesheets and is sometimes referred to as a universal selector.

Related

Difference in applying codes in elements [duplicate]

This question already has an answer here:
Difference in applying CSS to html, body, and the universal selector *?
(1 answer)
Closed 3 years ago.
I would like to ask what is the difference between *{} and body,html{}. It changes the view in the html and I want to have a broad knowledge about this. Thanks.
The wildcard (*) will apply the styling to every element found on your HTML page unless you give specific styling for that element. It overrides any possible inheritance for the set property because it is setting that default value for each individual element. If you want to change something in a section that has child elements then you will have to make that change for each child. This can be useful in a few cases (box-sizing is probably the most common use) but most of the time you will not want to use this. Depending on how heavily this is used, it can slow down your page load times.
Setting the styling with body/html allows for inheritance to still take place. Elements within the html/body will still show the styling found here if their default is set to inherit. This will still allow a closer parent to the child to override the styling. In CSS, the best option is to be more specific.
The *{} selector (Universal selectors) matches elements of any type. (MDN).
body,html{} select body and html elements.
Consider the following example:
* { /* Selects all elements */
color: blue;
}
html,
body { /* Selects html and body element */
color: green;
}
<html>
<body>Body</body>
<footer>footer</footer>
</html>
*{}
is a universal selector. It will implement the styling of all the elements. If you want to do some changes with styling of the particular element then you have to override it.
body,html{}
will do the same for you. But there is one scenario. If you want to inherit the properties from the parent then body,html{} is definitely going to play this role. It is used for the inheritance of properties

Difference between html and * when setting color or fonts for the whole page [duplicate]

This question already has an answer here:
Difference in applying CSS to html, body, and the universal selector *?
(1 answer)
Closed 3 years ago.
I watched a video and found the programmer used * {} to set the margin and padding, but used html {} to set the font color. I don't understand why he bothers to use html {} to set the font color? He could have used * {}
to set all those things.
The * wildcard rule essentially says this style applies to all elements. It's usually discouraged from use because that has performance implications. I suspect the author has a pet hate of elements with default margin or padding and just salts the earth because of it.
I recommend using a real CSS reset or normalising snippet instead, for example https://dev.to/hankchizljaw/a-modern-css-reset-6p3
The difference in this context between color and margin/padding is that color is inherited from an element's parent by default, and margin/padding doesn't.
So if we set * { color: green; }, we'd have to write another rule like p { color: inherit; } to get that inheritance behaviour back.

How can I prevent universal selector rules from affecting span? [duplicate]

This question already has answers here:
Can I write a CSS selector selecting elements NOT having a certain class or attribute?
(10 answers)
Closed 4 years ago.
I have this rule:
* {background-color:#ddd;font-family: Arial,Helvetica,sans-serif;font-size:13pt}
Unfortunately, it imposes the font-size on a < span > element. I want the span to continue to have no default rules so I can use it to change text color, etc.
My * rule has the lowest priority, which is good since * is used to set default values, which we want overridden easily. However, it applies to the span rule, which makes span erroneously include its styles. Span should be used to apply specific styles, not the default styles.
Use the :not pseudoselector to exclude span, as follows:
:not(span) {background-color:#ddd;font-family: Arial,Helvetica,sans-serif;font-size:13pt}

CSS Rule, Never seen before [duplicate]

This question already has answers here:
What does an asterisk (*) do in a CSS selector?
(5 answers)
Closed 9 years ago.
Ok, looking at some code in a CSS Stylesheet assigned to a project, I noticed this:
* {
margin: 0px;
padding: 0px;
text-decoration: none;
}
What does this bit do?? What elements does it effect exactly?? Strange, never heard tell of using the asterisks as a selector or whatever it is supposed to be for. What does the asterisk do exactly?
* affects (I should say "represents the qualified name of") all elements. Per spec:
http://www.w3.org/TR/selectors/#universal-selector
The asterisk is the 'universal selector' and applies the style to all elements on the page. This code will reset everything to have no margins, padding or text-decoration.
Universal selector on W3.org
It is the universal selector, much like the '$' in jQuery. It is usually used in the reset

Meaning of '*' in CSS [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
css: the meaning of * mark
What does * do in css? I saw some code here that contained it:
.center-wrapper{
text-align: center;
}
.center-wrapper * {
margin: 0 auto;
}
Is this a typo?
* means ALL.
In this case it would be ALL the elements in .center-wrapper
It's a wildcard, it matches every element. So in your example, it means every element that's a descendant of elements with the "center-wrapper" class.
According to the official W3C docs, it's called a "universal selector", see http://www.w3.org/TR/css3-selectors/#universal-selector:
The universal selector, written as a
CSS qualified name [CSS3NAMESPACE]
with an asterisk (* U+002A) as the
local name, represents the qualified
name of any element type.
means everthing: every tag/element in document.
In this case .center-wrapper * everything under every element with center-wrapper class.
* is Universal selector.
.center-wrapper * select all descendant elements of .center-wrapper.
* means that the styles assigned to it must be applied to the whole page. It is not a typo.
It means it will select all elements within that portion of the DOM.

Resources