SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using different css depending on browser

    I have run into problems using css in IE. So I want to enabled a css file with users who have IE and a different one with users who do not have IE. I know how to check to see what browser they have, but how do I activate the css file in javascript? I can't use document.writeln.
    Free Science Homework Help
    http://www.physicsforums.com

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To enable a CSS file just for IE, you're probably better off using a conditional comment
    Code:
    <!--[if IE]>
    	<link rel="stylesheet" type="text/css" href="styles/ie.css" />
    <![endif]-->
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    conditional comment
    Are you joking with me or is there really such thing as "conditional comments"? If so, is there a "not" clause too?
    Free Science Homework Help
    http://www.physicsforums.com

  4. #4
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    will this work?

    Code:
    <!--[if !IE]>
    <link rel="stylesheet" href="products.css" type="text/css">
    <![endif]-->
    
    <!--[if IE]>
    <link rel="stylesheet" href="products_IE.css" type="text/css">
    <![endif]-->
    Free Science Homework Help
    http://www.physicsforums.com

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Yes, there really is

    Check out the reference here. It's an IE-only thing - but they are helpful when you need some IE-only, um, finessing.

    The NOT operator exists - but I'm not sure how that will work with non-IE browsers. Read up on their docs - as there are several types of conditional comments.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that only IE is a problem, so it's either my page looks good in IE and nothing else or it looks good in everything else and not IE. If the broswer isn't IE then no CSS will load. I need a solution that will load one CSS if it's IE and another if the browser isn't IE.
    Free Science Homework Help
    http://www.physicsforums.com

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I edited my post
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  8. #8
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did you see my post after yours beetle?
    Free Science Homework Help
    http://www.physicsforums.com

  9. #9
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dethfire
    that only IE is a problem, so it's either my page looks good in IE and nothing else or it looks good in everything else and not IE. If the broswer isn't IE then no CSS will load. I need a solution that will load one CSS if it's IE and another if the browser isn't IE.
    You can do that by using the conditional comments method (that Beetle has shown you) to override an earlier stylesheet.

    Code:
    ...<head>
    
    <link rel="stylesheet" type="text/css" href="site.css" />
    <!--[if IE]>
      <link rel="stylesheet" type="text/css" href="ie.css" />
    <![endif]-->
    IE will use the second stylesheet to override the first.

    If the same CSS declaration exists in both, then IE will override the one appearing in site.css and use the one in ie.css instead.

    Whilst only IE understands the conditional comments, all other browsers will still recognise the standard comment markers and will ignore whatever falls in between them. <!-- this will be ignored -->
    This means they will still be using the declarations inside the site.css file.

    Browsers will use the most recent recognisable declaration before the markup tag is read.
    After all, that's the idea behind 'cascading stylesheets.



    I know I haven't explained this particularly well, but hopefully you'll get my meaning.
    Last edited by Bill Posters; May 22, 2003 at 09:32.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  10. #10
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks good to me, Bill [img]images/smilies/thumbs_up.gif[/img]
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  11. #11
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YES, THANK YOU! now if only IE would update the browser!!
    Free Science Homework Help
    http://www.physicsforums.com


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
  •