Prioritizing one class over another


#1

If you have two classes assigned to one element, with CSS properties that directly contradict each other, is there a way to choose which class would override the other one in that case? For example:
HTML:

<p class="test-1 test-2">Text</p>

CSS:

.test-1 {
color: red;
font-family: Arial;
}
.test-2 {
color: yellow;
text-decoration: underline;
}

Let’s say that I want the color to be yellow. Can I tell it to prioritize the “test-2” class over the “test-1” class, so that it will make it yellow instead of red? If so, how?


#2

I believe this is determined by the hierarchy of the css document, therefore the css document not only considers the position of the css rules, but also the css declarations

.test-1{color:blue;}
.test-2{color:blue; color:green; color: red;}
//the output of the paragraph will be in the color red

the last saved changes to the targeted element should always take effect!

.test-2{color:blue; color:green; color: red;}
.test-1{color:blue;}
//the output of the paragraph will be in the color blue

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.