Compiling and maintaining ie-specific stylesheets

前端 未结 2 624
遥遥无期
遥遥无期 2020-12-04 00:44

What is the common practice for maintaining IE workarounds in a separate CSS file? I\'m talking about deeper issues that are impractical to work out by othe

相关标签:
2条回答
  • 2020-12-04 01:21

    You can use JavaScript to add a class to the HTML based on the browser and other things - I find these really useful! This is the one I use http://rafael.adm.br/css_browser_selector

    0 讨论(0)
  • 2020-12-04 01:35

    Sass (version 3.2+) can do this fairly easily if you're ok with generating 2 different stylesheets.

    Here's your mixins:

    $ie-only: false !default;
    
    @mixin hide-from-ie {
        if $ie-only != true {
            @content;
        }
    }
    
    @mixin show-only-ie {
        if $ie-only == true {
            @content;
        }
    }
    

    In your SCSS files:

    .some-class-lets-say-datepicker {
        @include hide-from-ie {
            background-image: url(data:image/png;base64,/*encoded image*/);
        }
    
        @include show-only-ie {
            background-image: url(../gfx/lets-say-datepicker-icon.png);
        }
    }
    

    Make a separate IE-only file that imports your other SCSS files, but has this at the top:

    $ie-only: true;
    

    Use conditional comments to serve old IE versions the generated css file with $ie-only set to true, and every other browser gets the one generated with $ie-only set to the default false.

    Inspiration for this technique was found here: http://jakearchibald.github.com/sass-ie/

    0 讨论(0)
提交回复
热议问题