is there a css hack for safari only NOT chrome?

后端 未结 18 1530
旧时难觅i
旧时难觅i 2020-11-22 06:50

im trying to find a css hack for just safari NOT chrome, i know these are both webkit browsers but im having problems with div alignments in chrome and safari, each displays

相关标签:
18条回答
  • 2020-11-22 06:53

    Step 1: use https://modernizr.com/

    Step 2: use the html class .regions to select only Safari

    a { color: blue; }
    html.regions a { color: green; }
    

    Modernizr will add html classes to the DOM based on what the current browser supports. Safari supports regions http://caniuse.com/#feat=css-regions whereas other browsers do not (yet anyway). This method is also very effective in selecting different versions of IE. May the force be with you.

    0 讨论(0)
  • 2020-11-22 06:53

    You can use a media-query hack to select Safari 6.1-7.0 from other browsers.

    @media \\0 screen {}
    

    Disclaimer: This hack also targets old Chrome versions (before July 2013).

    0 讨论(0)
  • 2020-11-22 06:54

    At the end I use a little JavaScript to achieve it:

    if (navigator.vendor.startsWith('Apple'))
        document.documentElement.classList.add('on-apple');
    

    then in my CSS to target Apple browser engine the selector will be:

    .on-apple .my-class{
        ...
    }
    
    0 讨论(0)
  • 2020-11-22 06:55

    When using this safari-only filter I could target Safari (iOS and Mac), but exclude Chrome (and other browsers):

    @supports (-webkit-backdrop-filter: blur(1px)) {
      .safari-only {
        background-color: rgb(76,80,84);
      }
    }
    
    0 讨论(0)
  • 2020-11-22 07:01

    I like to use the following method:

    var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
    if (isSafari) { 
      $('head').append('<link rel="stylesheet" type="text/css" href="path/to/safari.css">') 
    };
    
    0 讨论(0)
  • 2020-11-22 07:02

    Note: If iOS-only is sufficient (if you're willing to sacrifice Safari desktop), then this works:

        @supports (-webkit-overflow-scrolling: touch) {
        /* CSS specific to iOS devices */ 
        }
    
    0 讨论(0)
提交回复
热议问题