W3C home > Mailing lists > Public > www-style@w3.org > January 2012

Re: @import -- allow at any place in stylesheet.

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Tue, 17 Jan 2012 10:49:45 -0800
Message-ID: <CAAWBYDAkfJJegmFeYB4zmVX-RDFp=6jYi1eb_g-gJAJC5CpWOA@mail.gmail.com>
To: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>
Cc: www-style@w3.org
2012/1/17 Marat Tanalin | tanalin.com <mtanalin@yandex.ru>:
> 17.01.2012, 20:14, "Tab Atkins Jr." <jackalmage@gmail.com>:
>> The restriction that @import has to appear at the top of a file is
>> meant, I believe, to make it easier to understand that other files are
>> being imported.  A lone @import in the middle of a file is easy to
>> accidentally skip over for a human.
> It's wrong and harmful to try think for web-developers and invent artificial unusable limitations as a result. Web-developers themselves are capable to decide how to use syntax. Imports/includes in PHP, SSI, etc., are possible at any place, and this is not an issue there.

Incorrect.  We must always guard against making the language too
complicated when the reward is just better behavior in an edge case.

> @imports could be allowed at least exactly at the end of stylesheet. Currently, to achieve same result, we are often forced to make order of including less logical. For example, we have main.css linked to HTML document, and override.css imported to main.css. We want that rules from override.css would override main.css rules with same specificity. For this purpose, rules from override.css have to appear in cascade _after_ rules from main.css. We could do this usable way:
>    <link rel="stylesheet" href="main.css" />
>    main.css:
>        /* ...
>           Some rules to be overridden.
>           ... */
>        @import "override.css";
> But currently we are forced to link to override.css instead of main.css to HTML document, and import main.css at the beginning of override.css:
>    <link rel="stylesheet" href="override.css" />
>    override.css:
>        @import "main.css";
>        /* ...
>           Some rules that override rules from main.css.
>           ... */
> All that just decreases flexibility.

The latter pattern is actually quite natural and easy to understand,
if you use different file names.  Instead of "main.css", call it
"template.css" or "defaults.css", and then instead of "override.css"
just call it "main.css".  It's then obvious and natural that you'd
directly reference the second file, and include the first file at its

Alternately, this works today:

@import "main.css";
@import "override.css";

Received on Tuesday, 17 January 2012 18:50:40 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:10 UTC