Is it possible to use @import in one css file like this.
@import file1
some css here
@import file2
chrome doesn't recognize the second import for the above but this will work
@import file1
@import file2
some css here
The problem here is I need "some css" to be in the middle because file2 will override some of them. Is there any other solution other than importing 3 files from html?
Style rules take precedence in right-to-left order. Rules to the right take precedence over rules to the left. Properties that are not declared are carried over and reapplied to succeeding style sheets.
The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.
CSS Order Matters In 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.
98. Why can @import be at the top only? A style sheet that is imported into another one has a lower ranking in the cascading order: the importing style sheet overrides the imported one. Programmers may recognize this as the same model as in Java, Modula, Object-Pascal, Oberon and other modular programming languages.
That is not possible:
From http://www.w3.org/TR/CSS21/cascade.html#at-import:
The '@import' rule allows users to import style rules from other style sheets. In CSS 2.1, any @import rules must precede all other rules (except the @charset rule, if present).
From http://www.w3.org/TR/CSS21/syndata.html#at-rules:
Assume, for example, that a CSS 2.1 parser encounters this style sheet:
@import "subs.css"; h1 { color: blue } @import "list.css";
The second '@import' is illegal according to CSS 2.1. The CSS 2.1 parser ignores the whole at-rule, effectively reducing the style sheet to:
@import "subs.css"; h1 { color: blue }
@import
s though. If you want to override properties in file 1, they can also be added after the @import
blocks. Properties which are overridden in file 2 can be omitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With