dsm...@flvs.net wrote: > I teach Web Design and really focus on standards and best practices. > When using external style sheets I have always had students link the > style sheet. Recently some students have begun using the @import > url("main.css");I understand how to use both. I am just wondering > what the best practice is and why.
The use of links vs. @imports is not so much a question about "best practice" as about strategy and file-structure. On source-code level one has a choice between links and @imports, and both can be used and misused. If hiding stylesheets from old and inferior browsers is part of the strategy, then @import, with and without media-attributes, is one method that can be used - with some success. Such trickery can also be achieved with stylesheet links. Good knowledge about how various browsers handle various link/@import constructions found in source-code, is essential, and there are several traps here. Add in methods like the not-yet-stable @media queries standards - for links, @import and @media, and one really has to be careful. ----- On CSS level one only has @import, but still many options. @importing stylesheets for various layout-parts and media into one main stylesheet which is then linked or @imported from the source-code, may work well for some of those who reuse stylesheets and prefer to keep all maintenance and upgrading at stylesheet level. Depending on strategy and structure the entire "hide from inferior browsers" can be moved from source-code to stylesheet level, and there's literally no end to how one can use or misuse browser-weaknesses and -quirks to achieve specific "hide/targeting" effects. Plenty of traps here too, and it's pretty easy to open up for future failures. ---- "Best practice" is to keep it as simple and close to standards as possible for the intended purpose, while observing how standards and browsers standards-support evolve. So, "best practice" is what works as intended now - being it links or @imports in this case, and it is of course an even "better practice" if it continues to work in the future. Many of the "best practice" methods promoted only a few years ago now - quite predictable - show signs of failure, so I'm reluctant to promote any "best practice" method other than one of constantly observing how all parts work together when seen from a standards point of view and in actual browsers. My own strategy is best met by using only links, with and without media-attributes, in the source-code, but this has nothing to do with "best practice" apart from that it'll always work as intended. regards Georg -- http://www.gunlaug.no ______________________________________________________________________ css-discuss [cs...@lists.css-discuss.org] http://www.css-discuss.org/mailman/listinfo/css-d List wiki/FAQ -- http://css-discuss.incutio.com/ List policies -- http://css-discuss.org/policies.html Supported by evolt.org -- http://www.evolt.org/help_support_evolt/