HighDots Forums  

link or @import

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss link or @import in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
steven
 
Posts: n/a

Default link or @import - 02-04-2004 , 12:02 PM






Which one is better:

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

or

<style type="text/css">
@import url("style.css");
</style>

and why?
TIA

Steven



Reply With Quote
  #2  
Old   
Peter Foti
 
Posts: n/a

Default Re: link or @import - 02-04-2004 , 12:19 PM






"steven" <stevenPANTSvh (AT) pandora (DOT) be> wrote

Quote:
Which one is better:

link rel="stylesheet" href="style.css" type="text/css" /

or

style type="text/css"
@import url("style.css");
/style

and why?
Some browsers don't support the @import method... most notibly NN4. I
recently switched from the link method to the @import method when I decided
I could stop supporting NN4 and let the page degrade gracefully on that
browser. Read this article for more on which browsers support which method
(note, there are variations using the @import method... URL with and without
quotes, etc. See this article:
http://w3development.de/css/hide_css_from_browsers/

Regards,
Peter Foti




Reply With Quote
  #3  
Old   
Keith Bowes
 
Posts: n/a

Default Re: link or @import - 02-04-2004 , 12:28 PM



steven wrote:
Quote:
Which one is better:

link rel="stylesheet" href="style.css" type="text/css" /

or

style type="text/css"
@import url("style.css");
/style

and why?
TIA

Neither's better. They're different. "link" is used for multiple
styles and for grouping different files into a single file. For
example, try this in Mozilla or Opera:
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="style1.css" type="text/css" title="Style 1" />
<link rel="alternate stylesheet" href="style2.css" type="text/css"
title="Style 2" />

style.css is persistent (like @import). But style1.css and style2.css
are selectable alternate styles. More info is in the HTML 4 spec.

Note that in certain browsers (such as IE), the distinction is blurred;
but per the spec (and in standards-oriented browsers), the two are very
different.

HTH



Reply With Quote
  #4  
Old   
David Dorward
 
Posts: n/a

Default Re: link or @import - 02-04-2004 , 02:10 PM



steven wrote:
Quote:
link rel="stylesheet" href="style.css" type="text/css" /
This is the XHTML way (lose the '/' and its the HTML way)

Quote:
style type="text/css"
@import url("style.css");
/style
This uses more markup, creates a new style sheet, then imports another style
sheet into it. Its rather inefficient IMO.

--
David Dorward <http://dorward.me.uk/>


Reply With Quote
  #5  
Old   
Peter Foti
 
Posts: n/a

Default Re: link or @import - 02-04-2004 , 02:33 PM



"David Dorward" <dorward (AT) yahoo (DOT) com> wrote

Quote:
steven wrote:
link rel="stylesheet" href="style.css" type="text/css" /

This is the XHTML way (lose the '/' and its the HTML way)

style type="text/css"
@import url("style.css");
/style

This uses more markup, creates a new style sheet, then imports another
style
sheet into it. Its rather inefficient IMO.
Uses more markup?! Barely, if at all. Consider this:

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

58 characters (not including the new line at the end).

Now consider this:

<style type="text/css">
@import url("style.css");
</style>

61 characters (not including the new line at the end). Note that I could
have removed the 3 spaces before @import to get 58 characters and it would
have been exactly the same as the link method. But indentation aside, they
are practically identical, and a few extra bytes is hardly a reason to not
use this method.

In addition, this method allows for stylesheets to be hidden from browsers
that implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.

Regards,
Peter Foti




Reply With Quote
  #6  
Old   
David Dorward
 
Posts: n/a

Default Re: link or @import - 02-04-2004 , 03:40 PM



Peter Foti wrote:

Quote:
In addition, this method allows for stylesheets to be hidden from browsers
that implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.
Yes you can:
<link ... media="screen,projection">


--
David Dorward <http://dorward.me.uk/>


Reply With Quote
  #7  
Old   
Peter Foti
 
Posts: n/a

Default Re: link or @import - 02-04-2004 , 04:06 PM



"David Dorward" <dorward (AT) yahoo (DOT) com> wrote

Quote:
Peter Foti wrote:

In addition, this method allows for stylesheets to be hidden from
browsers
that implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.

Yes you can:
link ... media="screen,projection"
Interesting. I thought that because NN4 supports media="screen" that the
above would still work with it. But apparently that's not the case. In
addition, this should ONLY exclude NN4, whereas the @import methods will
always exclude additional browsers (though in some cases, it may be better
to exclude more... namely IE3 and sometimes IE4).

Ok, you've converted me back to link again!

-Peter




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.