两次定义CSS属性 [英] Defining CSS properties twice

查看:118
本文介绍了两次定义CSS属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

general.css

general.css

#feedback_bar
{
  /*props*/
}

another.css

another.css

#feedback_bar
{
  /*props*/
}

可以吗?都会继承吗?

推荐答案

最后定义的属性将覆盖先前定义的属性.除非您在CSS的先前定义的部分上使用!important.

The properties defined last will override properties defined previously. Unless you use !important on the previously defined section of CSS.

.thing {
    padding: 10px;
}

.thing {
    padding: 12px;
}

.thing将具有padding: 12px;

.thing {
    padding: 15px !important;
}

.thing {
    padding: 123px;
}

.thing将具有padding: 15px;

这是允许的,并且为了更严格地回答您的问题,这两个示例确实都将被继承,如下例所示:

This is allowed, and to more strictly answer your question, both will indeed be inherited as shown by this example:

.thing {
    padding: 10px;
}

.thing {
    background: red;
}

.thing将同时具有padding: 10px;background: red;.

另外,请花一些时间阅读有关此答案的一些评论,因为它们提出了值得进一步阅读的要点.

Also, please take a moment to read some of the comments on this answer as they raise good points worth further reading.

这篇关于两次定义CSS属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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