Results 1 to 8 of 8

Thread: @import rule...

  1. #1
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Question @import rule...

    Ok, so I've just recently come across the @import rule in CSS, and I'm having a hard time finding any information about how to implement it... Does anyone have any idea how to do this? I looked on w3c.org but the only info they give doesn't really tell how to let users pick the style. It simply tells what to put in the external SS... I'm looking for info on how to implement it into the site so the user can pick and choose things like link colors and such. Unless my understanding of this rule is wrong, then that's exactly what it's designed for correct?
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    @import is another way of using external stylesheets like <LINK>

    Code:
    <STYLE TYPE="text/css">
    
      @import url("yourcssfile.css");
    
    </STYLE>

    You can safely drop the url( ) notation. The following example therefore has the same effect as the previous one:


    Code:
    <STYLE TYPE="text/css">
    
      @import "yourcssfile.css";
    
    </STYLE>
    When you are importing CSS using @import you need to specify <style></style> and the @import statement must be the first line.

    The most common use of @import is to hide incorrectly implemented CSS from IE4/NS4/O5 as they don't support @import so you can take advantage of that to present one type of CSS for them and different CSS for other browsers.

    Check this article to get more idea about hiding the CSS from some browsers

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nyne Lyvez View Post
    Ok, so I've just recently come across the @import rule in CSS, and I'm having a hard time finding any information about how to implement it ... I looked on w3c.org but the only info they give doesn't really tell how to let users pick the style.
    Users? Which users would those be? The import at-rule isn't meant to allow an end-user to select a style sheets, it's meant to be used to import rules from one style sheet so that the importing style sheet can build on them. That is, the imported style sheet contains some rules that the importing style sheet would like to use. Rather than copy the rules into the style sheet, it simply references them via the import at-rule.

    I'm looking for info on how to implement it into the site so the user can pick and choose things like link colors and such. Unless my understanding of this rule is wrong, then that's exactly what it's designed for correct?
    No. What you're looking for is alternate style sheets, which are controlled via link elements. I've described this a couple of times, and have posted both server-side (PHP) and client-side code that can be used to switch between style sheets for lesser browsers that don't give the user the option. See the three threads, style switching not work on IE, but works on everything else, looking for a minimal js styleswitcher script with cookies, and Dynamically changing ref to linked css file.


    Quote Originally Posted by codeexploiter View Post
    @import is another way of using external stylesheets like <LINK>
    Except at the style sheet level, not the markup level.

    When you are importing CSS using @import you need to specify <style></style>
    Not at all.

    and the @import statement must be the first line.
    Import at-rules must occur early, but not necessarily the first line: a charset at-rule can proceed them, as well as any number of comments. The important thing is that import at-rules must occur before rules, and media and page at-rules.

    Mike

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by mWinter
    Quote:
    When you are importing CSS using @import you need to specify <style></style>
    Not at all.
    Can you please tell me how to use the @import without the <style></style>?


    Quote Originally Posted by mWinter
    Quote:
    and the @import statement must be the first line.
    Import at-rules must occur early, but not necessarily the first line: a charset at-rule can proceed them, as well as any number of comments. The important thing is that import at-rules must occur before rules, and media and page at-rules.
    By the above statement i meant the following, i am sorry if it was ambiguous.

    "Any @import rules must precede all other rules (except the @charset rule, if present)."

    I think nobody consider the comments as actual style rules.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I believe the issue of the style tags is that you must have ANY CSS within style tags in html markup, but you don't need specific tags around the @import. For example, you don't need style tags when it isn't in html, such as the case with any standalone .css stylesheet


    I think the point of all this.... @import is to be used within other css, whereas <link....> is meant to be used to import css for html in general.


    One example of a situation that would be helped with this:
    You have several layouts for a page, or several pages with similar layouts.
    Let's assume that a good portion of the code remains the same, but only a few elements change, such as, perhaps, colors.

    What you could do is specify within each page (or through a style switcher) which color .css you want to use <link...> to set that .css file, as usual.
    However, in each of those specific color .css files, you can include the @import rule. That would allow you to include a third .css sheet containing all of the common traits of the layouts, without including in each of the variations based on color.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    understood it completely and thanks for the explanation

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Now, I'm not sure why it's "wrong" to use the rule just to replace the link markup, but I don't see why you should either. Generally, sticking to standards makes the most sense, "Just 'cause".
    And sure. Glad to help.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Now, I'm not sure why it's "wrong" to use the rule just to replace the link markup, but I don't see why you should either.
    I didn't write that it was "wrong", but it's not the purpose. Using import at-rules in style elements is more-or-less a parsing hack.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •