I came across a interesting code. If we run the below code snippet, green class will be applied for both the divs. Can anyone explain why?
.orange {
color: orange;
}
.green {
color: green;
}
<div class="orange green">Div 1</div>
<div class="green orange">Div 2</div>
The reason is because CSS is Cascading, so rules are applied according to how far down the file they are. If you switched .orange
to the bottom, you would have both <div>
s with orange text, and therefore with the class taking priority being orange
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments