Support » Fixing WordPress » Choosing CSS depending on browser

  • 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" />')
    document.write('<'+'style type="text/css" media="screen"><!-- @import url( <?php bloginfo("stylesheet_url"); ?> ); --></style/>')

    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) Admin

    You’d be better off using conditional comments:

    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.

    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"  />

    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.