Defining CSS properties twice

前端 未结 3 1666
北海茫月
北海茫月 2020-12-16 11:50

general.css

#feedback_bar
{
  /*props*/
}

another.css

#feedback_bar
{
  /*props*/
}

Is this allowed? Will

相关标签:
3条回答
  • 2020-12-16 12:18

    This is allowed, but if there are duplicate properties, the last one will be used.

    0 讨论(0)
  • 2020-12-16 12:30

    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 will have padding: 12px;

    .thing {
        padding: 15px !important;
    }
    
    .thing {
        padding: 123px;
    }
    

    .thing will have 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 will have both padding: 10px; and background: red;.

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

    0 讨论(0)
  • 2020-12-16 12:43

    The one that is loaded last overwrites the previous declaration(s). As for being allowed, css cannot throw errors at you :P. Probably not a good idea though.

    0 讨论(0)
提交回复
热议问题