CSS difference between ".cssClass object" and "object.cssClass"
I was doing some css today and was forced to change some syntax from:
input.cssClass
to
.cssClass input
How do these definitions differ, and when should we use ei开发者_如何学运维ther of them?
Wow, that is an odd change. The first will collect all the inputs
with class cssClass
, while the second will take all inputs
inside any element with cssClass
.
<body>
<input class="cssClass" type="text" />
<div class="cssClass">
<input type="text" />
</div>
</body>
So here, the first input will be grabbed by your first selector, while the second input will be grabbed by your second selector. Neither selector will grab both.
input.cssClass
will apply that style to input type objects that have that class specified.
.cssClass input
will apply that style to input type objects that are contained within any other object type that has the cssClass
class.
The first works with any input
element that has the class cssClass
:
<input class="cssClass" type="text" />
Whereas the second works with any input
element inside an element with class cssClass
, eg.:
<div class="cssClass">
<input type="text" />
</div>
精彩评论