/    Sign up×
Community /Pin to ProfileBookmark

Hello.

I’ve seen a few other websites which actually do this, but I wasn’t sure whether it’s a) “OK”, b) whether some browsers wouldn’t support it.

Basically, in the HTML itself within the head they have:

[code]<style type=”text/css” media=”all”>@import url(‘/css/foo.css’);</style>[/code]

Then, /css/foo.css just contains one line:

[code]@import url(‘/css/3rdoct04.css’);[/code]

Is this generally a bad idea?

I’d really like to use this, as it’s much easier for me to just edit “foo.css” instead of the HTML itself.

Thanks. ?

to post a comment
CSS

12 Comments(s)

Copy linkTweet thisAlerts:
@IncaWarriorOct 03.2004 — Yeah, that's one way, you can also use:

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

but you don't need to import it again in foo.css, you can just put all the CSS stuff there.
Copy linkTweet thisAlerts:
@TeachauthorOct 03.2004 — Hi, thanks for your reply.

Yes, I'm aware of this.

If you re-read my post you'll see why I want to do it that way...
Copy linkTweet thisAlerts:
@JonaOct 03.2004 — [font=trebuchet ms]It's a good idea to use the LINK tag for importing CSS, however NS4 understands it, to an extent, and usually doesn't look too great. So, it's probably best to use the LINK tag to an import.css file, which imports the main stylesheet file. If you use single-quotes in your import statement, I believe IE5/Mac won't get the stylesheet, either.[/font]
Copy linkTweet thisAlerts:
@Paul_JrOct 03.2004 — [font=palatino linotype]Opera seems to have a problem when importing styles like so: [size=1]@import "styles.css";[/size]. However, if I use the [size=1]LINK[/size] element to reference a stylesheet, and have only one line in the stylesheet, the import line, then Opera gets it just fine. ?[/font]
Copy linkTweet thisAlerts:
@IncaWarriorOct 03.2004 — I don't see why you would want to change the style sheet filename though
Copy linkTweet thisAlerts:
@Ben_RogersOct 03.2004 — Teach - @import is used in place of <link> in order to hide the stylesheet from earlier browsers which poorly support CSS.
Copy linkTweet thisAlerts:
@TeachauthorOct 03.2004 — Hiya.

Thanks for your replies.

Let me explain my original query a bit more clearly - I don't think I said it very clearly as no one has seemed to answer the original query properly. ?

Okay, some websites I've seen have a normal import line in their *HTML* i.e. <style type="text/css" media="all">@import url('/css/foo.css');</style>

foo.css would then just contain one line... i.e.:

@import url('/css/3rdoct04.css');

At the moment I just use the first method but I would like to use the above method of having the import in the HTML to foo.css and then just altering foo.css to the actual file that contains the CSS.

It's much easier for me to edit just foo.css if our CSS changes filename (as it is generated by dates) and saved as something like 3oct04.css than to go through each HTML file and edit the import in the HTML itself.

Hope this is a bit clearer. ?

I just tested it - and it's working fine on Opera 7.x, IE 6.01,5.5, 5.01, Firefox 0.8+, Safari 1.2 and more.

Regards,
Copy linkTweet thisAlerts:
@IncaWarriorOct 03.2004 — That doesn't mean much actually...

You should use the link method on the html pages then the import method on the stylesheet. Then you could even stick in an alternative stylesheet on foo.css for old browsers
Copy linkTweet thisAlerts:
@Paul_JrOct 03.2004 — [font=palatino linotype]I don&#8217;t see anything wrong with using that method, but how often does one&#8217;s CSS filename change&#8230;? [i]Why[/i] would it change? I, personally, use PHP to include my header onto each page, so if the filename changed I would just have to edit one file anyways (the header).[/font]
Copy linkTweet thisAlerts:
@IncaWarriorOct 04.2004 — Well his CSS files are based on the date for some reason and he probably doesn't use includes since he wants to set it using a file.
Copy linkTweet thisAlerts:
@Paul_JrOct 04.2004 — [i]Originally posted by IncaWarrior [/i]

[B]Well his CSS files are based on the date for some reason and he probably doesn't use includes since he wants to set it using a file. [/B][/QUOTE]

[font=palatino linotype]Ahh, all right. It&#8217;s actually a nifty way of being able to change the location/filename of the CSS file without having to go through all your pages and update the HTML.[/font]
Copy linkTweet thisAlerts:
@ray326Oct 04.2004 — That little level of indirection can be VERY handy from a configuration management standpoint. You can switch to a new style sheet and roll back very quickly if there are problems.
×

Success!

Help @Teach spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...