WordPress.org

Ready to get started?Download WordPress

Forums

Choosing CSS depending on browser (3 posts)

  1. dada44
    Member
    Posted 5 years ago #

    Hi people,

    I want my header.php to use one CSS if viewed in IE and another if viewed with any other browser.

    I'm doing:

    <script type="text/javascript">
    if (navigator.userAgent.indexOf("msie")!=-1){
    document.write('<'+'link type="text/css" media="screen" rel="stylesheet" href="<?php bloginfo("template_url"); ?>/ie.css" />')
    }else{
    document.write('<'+'style type="text/css" media="screen"><!-- @import url( <?php bloginfo("stylesheet_url"); ?> ); --></style/>')
    }
    </script>

    But it does not show any CSS at all. What am I doing wrong??
    The javascript is working fine out of WordPress ..

    Thanks in advance!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    You'd be better off using conditional comments:
    http://www.quirksmode.org/css/condcom.html

    Use one of those. Other browsers will ignore the comment, but IE will see it and read the link tag. Then you can put all your IE specific CSS in that extra file.

  3. dada44
    Member
    Posted 5 years ago #

    Thanks Otto, but I do not know if I'm getting it right ..
    I do:

    <!--[if gt IE 5]>
    <link type="text/css" media="screen" rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie.css"  />
    <![endif]-->

    But it does not work, IE6 doesn't use ie.css

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic