What are the implications of using the various selector configurations?
span.classy.whatever { }
span.classy, .whatever { }
span .classy .whatever { }
span, .classy, .whatever { }
What are the implications of using the various selector configurations?
span.classy.whatever { }
span.classy, .whatever { }
span .classy .whatever { }
span, .classy, .whatever { }
Period in CSS is used to denote the class selector. e;g;
Now as per your question Let see where these classes will take effect.
a. span.classy.whatever { }
: It will affect on span element which has classy and whatever both the classes.
<span id="mySpan" class="classy whatever"> Span Text </span>
b. span.classy, .whatever { }
: It will affect on span which has classy
class and the elements those have whatever
class.
<span id="mySpan" class="classy"> Span Text </span>
<div class="whatever"></div>
c. span .classy .whatever { }
: It will affect on the element which has whatever class and the parent of this element would be classy
and the parent of classy
would be span.
<span>
<span class="classy">
<span class="whatever">
inner most child
</span>
</span>
d. span, .classy, .whatever { }
: It will affect on the span, elements of classy class and whatever class.
<span>Span Text</span>
<div class="classy"></div>
<p class="whatever"></p>
1) will apply to all the spans with .classy and .whatever classes.
2) will apply to all the spans with .classy and all the elements with .whatever classes
3) will apply to all the elements with .whatever class which should be a child of an element with class .classy which inturn should be a child of a span. eg
<span>
<div class="classy">
<div class="whatever">This will be targeted</div>
</div>
</span>
4) will apply to all spans, .classy and .whatever classes
They all mean different things and select different elements.
span.classy.whatever { }
The rules are applied to a <span>
element that belongs to a class classy
and a class whatever
.
span.classy, .whatever { }
The rules are applied to a <span>
element that belongs to a class classy
, and to ANY element that belongs tho the class whatever
.
span .classy .whatever { }
The rules are applied to an element that belongs to the whatever
class that in a descendant of an element that belongs to the classy
class that is a descendant of a <span>
element.
span, .classy, .whatever { }
The rules are applied to ANY <span>
element, ANY element that belongs to the classy
class and ANY element that belongs to the whatever
class.
span.classy.whatever { }
This will match a span
element, that has a class of classy
and whatever
span.classy, .whatever { }
Will match a span
element that has a class of classy
and any
element with the whatever
class
span .classy .whatever { }
Will match a nested element
<span>
<span class="classy">
<span class="whatever">here</span>
</span>
</span>
And finally
span, .classy, .whatever { }
Will match all span
elements, and any
element with with a class of classy
and any element with a class of whatever
span.classy.whatever { }
Targets span
elements with both .classy
and .whatever
classes
span.classy, .whatever { }
Targets span
elements with the class .classy
and any element with the class .whatever
span .classy .whatever { }
Targets elements that have the class .whatever
that are the children of elements with the class .classy
that are children of span
elements.
span, .classy, .whatever { }
Targets any span
element, and any elements with either the class .classy
or .whatever