Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining CSS properties twice

Tags:

general.css

#feedback_bar {   /*props*/ } 

another.css

#feedback_bar {   /*props*/ } 

Is this allowed? Will both get inherited?

like image 299
Chris Muench Avatar asked May 19 '11 23:05

Chris Muench


People also ask

How many CSS properties are there in total?

W3Schools lists 228 of them.

Are CSS classes inherited?

font-style, etc. The color property is also inherited. CSS properties such as height, border, padding, margin, width, etc. are not inherited naturally.

What is custom properties in CSS?

Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific values to be reused throughout a document.


2 Answers

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.

like image 51
Marty Avatar answered Nov 06 '22 00:11

Marty


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.

like image 21
Uku Loskit Avatar answered Nov 06 '22 00:11

Uku Loskit