Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts

    Pros and cons of importing

    I've seen two ways to reference external style sheets, @import and link/href. What would be the advantage/disadvantage of

    Code:
    <style type="text/css" media="screen, projection">@import "main.css";</style>
    versus

    Code:
    <link href="main.css" rel="stylesheet" type="text/css"/>
    ?

    Just want to make sure I do things the most standards-compliant way.

  • #2
    Regular Coder
    Join Date
    Apr 2008
    Location
    Manila, Philippines
    Posts
    262
    Thanks
    3
    Thanked 12 Times in 12 Posts
    import css is when you have two external style sheets... for example a page has two style sheets, one is for the general browsers.. and the second one for hacks... but most i see in that format is when one for ie browsers and the other one, for ff and other css compliant browsers..

  • #3
    Regular Coder Candygirl's Avatar
    Join Date
    Apr 2008
    Location
    Switzerland
    Posts
    183
    Thanks
    3
    Thanked 56 Times in 56 Posts
    @import is not understand by old browsers. It can be useful to hide your css for those browsers to prevent the sites being hard or impossible to watch because of css properties poorly or not interpreted.

    Here is some pages with different syntaxes regarding of which browser can read it or not: http://imfo.ru/csstest/css_hacks/import.php or http://centricle.com/ref/css/filters/

    The one you've written is a good one to prevent generation 4 browsers to read the css. For exemple, the way we use css today can really be nasty in netscape 4.x. Now the question might be: are they really some people still using IE or NS 4.x ?

    More generally @import could be useful to call a stylesheet from another stylesheet, link to use alternate stylesheets.
    I've read some intervention about bad performances using imbrication of @import.
    Last edited by Candygirl; 05-23-2008 at 03:35 PM.
    "Imagination was given to man to compensate for what he is not;
    a sense of humour to console him for what he is."
    -Francis Bacon

  • #4
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    I prefer the link method. I don’t particularly enjoy style blocks or inline styles. As said, not many people still use such old browsers and if they do they’re probably really used to see terrible layout by now.

  • #5
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Ah ha... Thanks. I just use a conditional comment to call alternate style sheets:

    Code:
    <!--[if IE]>
    <link href="ie.css" rel="stylesheet" type="text/css"/>
    <![endif]-->
    Seems to take the guesswork out of knowing which browser will read it and which won't, without the online references.

    How many people are using the older browsers really is the question. I code for IE6, 7, FF, Safari and Opera and call it a day.


  •  

    Posting Permissions

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