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.
Related
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
This question already has answers here:
CSS - Is it possible to select multiple different child elements within a parent without repeating the parent?
(3 answers)
Closed 8 years ago.
I am writing some rules in CSS for some elements that shares the same parent.
#parent_id li
#parent_id label,
#parent_id input,
#parent_id select { ... }
Is there an alternative syntax to avoid to repeat the parent id?
No there is not in pure CSS, but you can use some CSS preprocessor like:
LESS CSS http://lesscss.org/
Sass http://sass-lang.com/
Switch CSS http://sourceforge.net/projects/switchcss/
...or other
If those elements you're selecting are all the elements within the parent element, you could just apply the style to the parent element:
#parent_id {
....
}
Styles in there should be inherited down so that the elements inside it are get those styles as well.
Another option might be to use the universal * selector:
#parent_id * {
....
}
This will affect all elements at least one level below the parent_id element, but not parent_id itself. If you've got plain text in parent_id that you want to leave unaffected, this might be the one to use.
A third option would be to change your HTML markup so that the elements you want to affect have a class. Then your CSS could simply reference that class instead.
(btw - yes, I'm aware of LESS/SASS/etc, but I didn't think there was much value in posting the same answer as everone else)
CSS native dont support this. But you can use SASS/LESS:
#parent_id {
label, input, select { ... }
}
In simple css it is not possible. Try LESS to achieve this.
I found some stylesheets using * symbol on it. for example *zoom: 1; what does the * symbol stands. sometimes which appears like [class*="span"] this. can anybody clear me the usage of the symbol * in css
*zoom is a hack that applies it ie6 and ie7. * { } is a wildcard (matches all elements or subset; if used like #header * it would apply to all descendants of #header). [class*="span"] matches elements that have a class with the word "span" anywhere.
If * is used an independent selector, it means all.
But if used inside the attribute selector [ ], it means "contains". For example, you have
[class*="span"]
. It means, it will select all elements that has a class which has a "span" somewhere in the class name.
It also used as CSS hack if it's inside the style value.
It is a wildcard which select all elements.
For example, if you apply margin to every element on entire page you can use:
* {
margin: 50px;
}
You can also use this within sub-selections, for example the following would add a margin to all elements within a paragraph tag:
p * {
margin: 10px;
}
See this:- http://www.stackoverflow.com/a/1204290/2256325
Regarding you example, let me tell you that if you add asterisk (*) immediately before a property name, the property will be applied in IE and not in other browsers. Its only applicable to version 7 or below .
Source :-http://www.javascriptkit.com/dhtmltutors/csshacks3.shtml
In addition to using the asterisk (at the start of a property name) to select only for older IE browsers, for CSS the many varied details are at w3.org:
CSS2.1 -- http://www.w3.org/TR/CSS21/selector.html
CSS3 -- http://www.w3.org/TR/css3-selectors/
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
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.