473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

link or @import

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
Jul 20 '05 #1
7 11790
"steven" <st***********@pandora.be> wrote in message
news:kA*******************@phobos.telenet-ops.be...
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
Jul 20 '05 #2
steven wrote:
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

Jul 20 '05 #3
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.

--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #4
"David Dorward" <do*****@yahoo.com> wrote in message
news:bv*******************@news.demon.co.uk...
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
Jul 20 '05 #5
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">
--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #6
"David Dorward" <do*****@yahoo.com> wrote in message
news:bv*******************@news.demon.co.uk...
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
Jul 20 '05 #7
Peter Foti wrote:

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.


Of course you can. Use the @import statement in the stylesheet that is
<link>ed. That introduces 2 stylesheets, I suppose, but it's how I've
always done it.

--
Brian (follow directions in my address to email me)
http://www.tsmchughs.com/

Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
2
by: ms | last post by:
In Access 2000, I am using... 'Import Raw text to stageBMIDLog table. DoCmd.TransferText acImportFixed, "BMIDLog Link Specification", "stageBMIDLog", file ....to import raw records into a...
3
by: David | last post by:
Hi, We a have a small office network of 3 users. Each user has their own copy of an MS Access Front-End which is linked via their own local ODBC connection to our server's MySQL database (Linux...
9
by: Arancaytar | last post by:
I have so far seen two methods for including external resources as CSS stylesheets in a document. The first is this: <link href="/stylesheets/style.css" rel="stylesheet" type="text/css" /> And...
0
by: Naha | last post by:
Hi guys, I am trying to link a jsp and servlets using beans, but how do I declare the id in the servlet. I can't seem to link them both. Help!!!!! Thanks in advance. Below is the jsp and...
0
by: George3 | last post by:
Hello everyone, 1. After my study, the address of IAT of an executable is known at compile/link time, other than known at load/runtime, right? I have this confusion because if an EXE...
4
by: bvdp | last post by:
Terry Reedy wrote: <snip> <snip> <snip>
10
by: nisp | last post by:
Hi all ! I'm trying to capture stderr of an external module I use in my python program. I'm doing this by setting up a class in my module overwriting the stderr file object method write. The...
1
by: dbphydb | last post by:
Hi, Im basically from QA. I have a piece of code in python that parses HTML pages to reach to a specific link on a webpage. The below code gets me the url of the link which needs to be clicked....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.