97

Recently I came across * * in CSS.

Site reference - Site Link.

For a single * usage in CSS style sheet, Internet and Stack Overflow is flooded with examples, but I am not sure about using two * * symbol in CSS.

I googled it, but unable to find any relevant information about this, as a single * selects all elements, but I am not sure why the site used it twice. What is the missing part for this, and why is this hack used (if it is a hack)?

0

5 Answers 5

138

Just like any other time you put two selectors one after another (for example li a), you get the descendant combinator. So * * is any element that is a descendant of any other element — in other words, any element that isn't the root element of the whole document.

Sign up to request clarification or add additional context in comments.

5 Comments

thx for the reply..this is what I was thinking for but not sure so thought to ask from the community..will accept it soon +1
just one more thing to ask--is it really relevant to use * * ? as although I grasp the concept but not getting it in practical terms :(
@swapnesh it looks like a browser hack. There's a * { font-size: XXX } rule and a * * { font-size: YYY } rule. One of them applies to most browsers, and the other one applies to browsers with a certain bug, although I don't have patience to figure out the details. It's similar to the * html hack that used to be in common use to detect old IE.
thx for adding the last detailed block under comments..it is almost a perfect one..no need to do more brain storming for that :) thx a lot :)
Note that in the manner of * html, * * will match the html element in IE6.
80

Just a little big example:

Try to add this on your site:

* { outline: 2px dotted red; }
* * { outline: 2px dotted green; }
* * * { outline: 2px dotted orange; }
* * * * { outline: 2px dotted blue; }
* * * * * { outline: 1px solid red; }
* * * * * * { outline: 1px solid green; }
* * * * * * * { outline: 1px solid orange; }
* * * * * * * * { outline: 1px solid blue; }

Demo: http://jsfiddle.net/l2aelba/sFSad/


Example 2:

What does the * * CSS selector do?

Demo: http://jsfiddle.net/l2aelba/sFSad/34/

2 Comments

This isn't strictly the answer, but what a lovely visualisation!
@l2aelba really a nice piece of explanation :) +1
33

* * Matches everything except the top-level element, e.g., html.

2 Comments

Thanks Joe, tested it here and also according to comments above: the * * selector is equivalent to html * for all browsers except the old good IE6 :-)
@Stano * * is equivalent of html * ... for a HTML file. But CSS may be used to style other kind of documents (SVG notably).
11

* means apply given styles to all the elements.

* * means apply given styles to all the element's child elements. Example:

body > * {
  margin: 0;
}

This applies margin styles to all the child elements of body. Same way,

* * {
  margin: 0;
}

applies margin: 0 to *'s child elements. In short, it applies margin: 0 to almost every element.

Generally, one * is enough. There's no need for two * *.

2 Comments

thx for the explanation +1 ..although even I am not sure for what you just mentioned in the last line "Generally, * is enough. There's no need for * *. I guess."
* * applies styles to descendant elements, not child elements. Child elements would be > as in your example, not the space. Descendant and child are not the same thing.
7

That selects all elements nested inside another element in much the same way div a would select all <a> elements nested somewhere inside a <div> element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.