How to use a different stylesheet for iphone or android?

前端 未结 5 2089
甜味超标
甜味超标 2021-01-15 11:07

I\'m trying to make a page where some elements will be visible only for android and iphone. I was thinking of using simple css properties to hide the elements e.g.:

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-15 11:45

    You can do it by javascript like:

    As per these points

    img1: displayed only on devices other than iphone and android    
    img2: displayed only on iphone and android devices
    img3: displayed only on iphones    
    img4: displayed only on android devices
    img5: displayed only on all devices
    

    CSS

    .show{display:block;}
    .hide{display:none;}
    

    HTML

    SCRIPT

    var IS_IPHONE = navigator.userAgent.match(/iPhone/i) != null;
    var IS_ANDROID = navigator.userAgent.match(/Android/i)  != null;
    
    if(IS_IPHONE)
    {
        $('#image3, #image2').removeClass('hide').addClass('show');
    }
    else if(IS_ANDROID)
    {
        $('#image4, #image2').removeClass('hide').addClass('show');
    }
    else
    {
        $('#image1').removeClass('hide').addClass('show');
    }
    $('#image5').removeClass('hide').addClass('show');
    

提交回复
热议问题