Is there any chance, a div call a particular css and its class. when i include two css on my html header both are have some same class.In case i have css1
.h1 text-align:center;color:red;
and css2
.h1 text-align:left;color:blue;.Now i need to call cssl from a div with h1 class in css1.

Recommended Answers

All 4 Replies

I suspect the best approach is if you are unable to have unique classes and ids, then if you need to ensure that a specific style is applied, use the "!important" rule to ensure that the styles you need to ensure are applied, do get applied. Styles are normally applied in order as they are read by the browser. So for example,

.h1 {text-align:center;color:red !important;}
.h1 {text-align:center;color:blue;}

In this example, the color red will be applied regardless of the order the styles come into the browser.

@JorgeM.. so what happens to the blue colour in this case? I never used the !important rule.

The blue is not applied. The !important will stick.

I don't get why someone would even bother defining a second colour... Is that in the case where if a colour that has !important rule defined on, fails then the second colour will be applied automatically?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.