0

I would like to create separate style-sheets, one for all IE versions and another one for "normal browsers" ;)

David Martins
  • 1,830
  • 6
  • 22
  • 30

4 Answers4

1
<!DOCTYPE html>
<html>
<head>
    <title> overwrite cssText if IE.  ewww nasty.  </title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type=text/css>
        body { font-family:'Segoe UI',sans-serif; font-size:14pt; color:black }
        #customLook { display:inline-block; margin-top:50px; margin-left:50px }
    </style>
    <link id=animstyle rel=stylesheet type=text/css href=animstyle.css>
    <script>
        var s= (animstyle.sheet||animstyle.styleSheet)                  // w3c-browser OR ie8
        if (s && s.cssText) s.cssText= ".customSpan:before{content:'not ';color:red}"   // only IE implements sheet.cssText  (including Edge)  it's r/w.
    </script>
</head>
<body>
    <div id=customLook>
        <span class=customSpan>ANIMATED</span>
    </div>
</body>
</html>



try this online demo

Actually, you could put s.disabled=true instead, and then enable some other css link.  That'd be more proper.  But I just had to post this, because it's so nasty.


Edit  Here's an easy way to disable one sheet and replace it with another:


        <link id=animstyle rel=stylesheet type=text/css href=animstyle.css>
        <script>
            var s= (animstyle.sheet||animstyle.styleSheet)                  // w3c-browser OR ie8
            if (s && s.cssText) s.disabled= true                        // only IE implements sheet.cssText  (including Edge)  it's r/w.
        </script>
        <link rel=stylesheet type=text/css href=NOanimstyle.css onload="(this.sheet||this.styleSheet).disabled=!s.disabled">

demo ver2
user4749485
  • 1,028
  • 7
  • 10
  • Hi, Thanks for helping. Your demo certainly works. At least in IE11. Would this work for all IE versions? If that's the case I'd like to use this. I'm just not sure how it works. Sorry for being a complete illiterate regarding JavaScript. Are you suggesting I use one style-sheet that includes the animations and another one that doesn't? That could work for me... Where exactly would I place the second style-sheet link? – David Martins Aug 04 '15 at 07:02
0

You can use browser sniffing - something like How can I target only Internet Explorer 11 with JavaScript? and then load the right stylesheet using document.write (see When using document.write to load a different css stylesheet, browser refreshes infinitely)

Community
  • 1
  • 1
potatopeelings
  • 40,709
  • 7
  • 95
  • 119
0

You might find the answers your looking for here

Appears to have been answered already

Community
  • 1
  • 1
Doug
  • 547
  • 10
  • 23
0

You can allways to something like this

<script>
var ltie11 = /msie/.test(navigator.userAgent.toLowerCase());
var ie11 = /Trident/.test(navigator.userAgent);
if( ! (ltie11 || ie11) ) {
    var $link = $('<link>').attr('type','text/css').attr('src', 'css/css.css');
    $('body').append($link);
}
</script>
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378