Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to give one CSS class priority over another?

Tags:

css

Say I have a div that uses two css classes that both use text-align, but one is centered and the other is right aligned.

Is it possible to specify something that will give one class priority over the other?

like image 650
Abe Miessler Avatar asked Sep 08 '10 20:09

Abe Miessler


People also ask

Which CSS is given more priority?

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 one CSS class refer to another?

You can just add a comma-separated list of classes in . radius , like . radius, . another, .

Which class takes priority CSS?

Inline CSS has a higher priority than embedded and external CSS. So final Order is: Value defined as Important > Inline >id nesting > id > class nesting > class > tag nesting > tag.

Does order of classes in CSS matter?

CSS Order MattersIn 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.


Video Answer


1 Answers

  1. specify a more specific selector, eg prefix an ID before it or prefix the nodename before the class
  2. assign it after the other class
  3. if two classes are in separate files, import the priority file second
  4. !important

!important is the lazy way, but you really should go for #1 to avoid important-ception. Once you've added one !important you can't use it to make some other rule even more important.

like image 66
meder omuraliev Avatar answered Sep 20 '22 01:09

meder omuraliev