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

17.01.2012, 22:49, "Tab Atkins Jr." <jackalmage@gmail.com>:
> 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.

There is no any complication here. We already have @import construct. We just should be able to insert it _between_ and _after_ rules and get rid of "only before other rules" theoretical limitation. And again (since apparently ignored): imports/includes in PHP, SSI, etc., are possible at any place, and this is not an issue there.

>> š@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
> top.

The thread is not about naming, but about flexibility.

> Alternately, this works today:
>
> <style>
> @import "main.css";
> @import "override.css";
> </style>

We can't, we are _forced_ to.

It would be nice improvement of core CSS syntax if web-developers would get able to link to one CSS file in HTML document, and then to flexibly control cascading on pure CSS level.

Received on Tuesday, 17 January 2012 20:51:40 UTC