Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there reasons to still use the "@import" css rule?

I recently came across a use of the @import rule on Coda.com. They're actually using to import the main style sheet for the site, specifically the format:

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

Which will hide the rules from Netscape 3 and IE 3 and 4. Since a web development tools primary audience will be using modern browsers, what other reasons would there be to use this rather then a link?

like image 915
FriendOfFuture Avatar asked Feb 12 '09 23:02

FriendOfFuture


2 Answers

None. Using a <link> element also has the advantage of getting rid of the FOUC.

EDIT: Using @import in another stylesheet (.css file) can be used like an #include in C, but there isn't any reason to use @import in a <style> block.

like image 163
Sophie Alpert Avatar answered Oct 12 '22 13:10

Sophie Alpert


For Coda's site, I'd imagine they did that more out of force of habit rather than any pressing technical need.

@import statements inside of actual CSS files (not in a <style> element in HTML) serve many purposes, such as making it easy to swap in and out other CSS files. The Blueprint CSS framework does this to let you easily remove certain portions of the framework such as the typography stuff or the grid stuff.

Of course, in a production environment, using a bunch of @import statements is frowned down upon because it increases the number of files a web browser has to pull down.

like image 30
Tyson Avatar answered Oct 12 '22 13:10

Tyson