是否可能给一个CSS类优先级别另一个? [英] Is it possible to give one CSS class priority over another?

查看:155
本文介绍了是否可能给一个CSS类优先级别另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个div,它使用两个CSS类,它们都使用text-align,但是一个是居中,另一个是右对齐。

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?

推荐答案


  1. 指定更具体的选择器,例如在其前面添加一个ID或在该类之前加上nodename

  2. / li>
  3. 如果两个类位于单独的文件中,则导入优先级文件

  4. !important

!important 是惰性的方式,但你真的应该去#1避免重要的。一旦您添加了一个!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.

这篇关于是否可能给一个CSS类优先级别另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆