div.classname vs div .classname
div.classname:This selector targets
<div>elements that have the classclassname.Example:
<div class="classname">This div will be styled</div> <div class="another-class">This div will not be styled</div>div.classname { color: red; }Only the first
<div>will have its text color set to red because it has the classclassname.
div .classname:This selector targets any element with the class
classnamethat is a descendant of a<div>element.Example:
<div> <span class="classname">This span will be styled</span> </div> <p> <span class="classname">This span will not be styled</span> </p>div .classname { color: blue; }Only the first
<span>will have its text color set to blue because it is inside a<div>element.
Last updated