View Full Version : Pros and cons of importing

05-23-2008, 03:29 PM
I've seen two ways to reference external style sheets, @import and link/href. What would be the advantage/disadvantage of

<style type="text/css" media="screen, projection">@import "main.css";</style>


<link href="main.css" rel="stylesheet" type="text/css"/>


Just want to make sure I do things the most standards-compliant way.

05-23-2008, 03:50 PM
import css is when you have two external style sheets... for example a page has two style sheets, one is for the general browsers.. and the second one for hacks... but most i see in that format is when one for ie browsers and the other one, for ff and other css compliant browsers..

05-23-2008, 04:28 PM
@import is not understand by old browsers. It can be useful to hide your css for those browsers to prevent the sites being hard or impossible to watch because of css properties poorly or not interpreted.

Here is some pages with different syntaxes regarding of which browser can read it or not: http://imfo.ru/csstest/css_hacks/import.php or http://centricle.com/ref/css/filters/

The one you've written is a good one to prevent generation 4 browsers to read the css. For exemple, the way we use css today can really be nasty in netscape 4.x. Now the question might be: are they really some people still using IE or NS 4.x ?

More generally @import could be useful to call a stylesheet from another stylesheet, link to use alternate stylesheets.
I've read some intervention about bad performances using imbrication of @import.

05-23-2008, 05:12 PM
I prefer the link method. I don’t particularly enjoy style blocks or inline styles. As said, not many people still use such old browsers and if they do they’re probably really used to see terrible layout by now.

05-23-2008, 05:13 PM
Ah ha... Thanks. I just use a conditional comment to call alternate style sheets:

<!--[if IE]>
<link href="ie.css" rel="stylesheet" type="text/css"/>

Seems to take the guesswork out of knowing which browser will read it and which won't, without the online references.

How many people are using the older browsers really is the question. I code for IE6, 7, FF, Safari and Opera and call it a day.