is there a css hack for safari only NOT chrome?

2018-12-31 14:02发布

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 differently.

i have been trying to use this but it affects chrome as well,

@media screen and (-webkit-min-device-pixel-ratio:0) { 
  #safari { display: block; } 
} 

does anyone know of another one that will just apply to safari please?

标签: css safari
13条回答
伤终究还是伤i
2楼-- · 2018-12-31 14:40

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.

查看更多
忆尘夕之涩
3楼-- · 2018-12-31 14:40

hi i ve made this and it worked for me

@media(max-width: 1920px){
    @media not all and (min-resolution:.001dpcm) {

        .photo_row2 {
            margin-left: 5.5% !important;
        }
    }
}

@media(max-width: 1680px){
    @media not all and (min-resolution:.001dpcm) {

        .photo_row2 {
            margin-left: 15% !important;
        }

    }
}

@media(max-width: 1600px){
    @media not all and (min-resolution:.001dpcm) {

        .photo_row2 {
            margin-left: 18% !important;
        }

    }
}


@media (max-width: 1440px) {
@media not all and (min-resolution:.001dpcm) {

        .photo_row2 {
            margin-left: 24.5% !important;
        }

    }

}


@media (max-width: 1024px) {
@media not all and (min-resolution:.001dpcm) {
    @media {
        .photo_row2 {
            margin-left: -11% !important;
        }

    }

}
查看更多
时光乱了年华
4楼-- · 2018-12-31 14:41

This hack 100% work only for safari. I've just tested it with success.

@media only screen and (-webkit-min-device-pixel-ratio: 1) {
     ::i-block-chrome, .yourcssrule {
        your css property
    }
}
查看更多
临风纵饮
5楼-- · 2018-12-31 14:42

It working 100% in safari..i tried

@media screen and (-webkit-min-device-pixel-ratio:0) 
{
::i-block-chrome, Class Name {your styles}
}
查看更多
路过你的时光
6楼-- · 2018-12-31 14:43

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">') 
};
查看更多
不流泪的眼
7楼-- · 2018-12-31 14:50

Replace your class in (.myClass)

/* Safari only */ .myClass:not(:root:root) { enter code here }

查看更多
登录 后发表回答