• 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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You’d be better off using conditional comments:
    https://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.

    Thread Starter dada44

    (@dada44)

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Choosing CSS depending on browser’ is closed to new replies.