Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple CSS Classes: Properties Overlapping based on the order defined [duplicate]

Is there a rule in CSS that determines the cascading order when multiple classes are defined on an element? (class="one two" vs class="two one")

Right now, there seems to be no such effect.

Example: both divs are orange in color on Firefox

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"    "http://www.w3.org/TR/html4/strict.dtd">  <html>   <head>     <style>       .one { border: 6px dashed green }       .two { border: 6px dashed orange }     </style>   </head>    <body>    <div class="one two">     hello world   </div>    <div class="two one">     hello world   </div> 
like image 556
nonopolarity Avatar asked Jun 17 '10 23:06

nonopolarity


People also ask

Does the order of CSS classes matter?

CSS Order Matters In CSS, the order in which we specify our rules matters. If a rule from the same style sheet, with the same level of specificity exists, the rule that is declared last in the CSS document will be the one that is applied.

When two CSS rules affect the same tag or context then the one specified later will win?

If the CSS specificity is the same for the conflicting rules, then the later one (the one defined later in the stylesheet or in the later stylesheet) takes precedence. The order of the class names on the object itself does not matter.

What is the order of priority of CSS?

Summary. Now we can say that the priority of the CSS property in an HTML document is applied top to bottom and left to right. Values defined as Important will have the highest priority. Inline CSS has a higher priority than embedded and external CSS.

Can multiple selectors can apply the same style?

When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet. Instead of having two, three, or more CSS rules that do the same thing (set the color of something to red, for example), you use a single CSS rule that accomplishes the same thing.


1 Answers

It depends on which one is declared last in your stylesheet. For example,

.one { border: 6px dashed green } .two { border: 6px dashed orange } 

vs

.two { border: 6px dashed green } .one { border: 6px dashed orange } 
like image 144
edl Avatar answered Nov 04 '22 15:11

edl