Media query to target iphone/mobile/ipad

后端 未结 3 1545
孤城傲影
孤城傲影 2021-02-04 23:06

I am using media query to target iphone/ipad/mobile.

I have written the following media query.

But my problem is if i write css in media query of mobile \'max-d

相关标签:
3条回答
  • 2021-02-04 23:23

    Rajnikant's answer is indeed the correct one, except that the iPad max-width is wrong. It should be 768px:

    /* For ipad: */
    @media screen and (max-width : 768px){} 
    
    0 讨论(0)
  • 2021-02-04 23:34

    I took the answer from http://cssmediaqueries.com/target/

    //HTC One, Samsung Galaxy S5, OnePlus One
    @media screen and (device-width: 360px) and (device-height: 640px) and (-webkit-device-pixel-ratio: 3)
    
    //Samsung Galaxy S2
    @media screen and (device-width: 320px) and (device-height: 534px) and (-webkit-device-pixel-ratio: 1.5)
    
    //Samsung Galaxy S3
    @media screen and (device-width: 320px) and (device-height: 640px) and (-webkit-device-pixel-ratio: 2)  
    
    //Samsung Galaxy S4
    @media screen and (device-width: 320px) and (device-height: 640px) and (-webkit-device-pixel-ratio: 3)  
    
    //LG Nexus 4
    @media screen and (device-width: 384px) and (device-height: 592px) and (-webkit-device-pixel-ratio: 2)
    
    //LG Nexus 5, Huawei Ascend P7
    @media screen and (device-width: 360px) and (device-height: 592px) and (-webkit-device-pixel-ratio: 3)
    
    //Asus Nexus 7
    @media screen and (device-width: 601px) and (device-height: 906px) and (-webkit-min-device-pixel-ratio: 1.331) and (-webkit-max-device-pixel-ratio: 1.332)  
    
    //iPad 1, iPad 2, iPad Mini
    @media screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 1)
    
    //iPad 3, iPad 4
    @media screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) 
    
    //iPhone 3G
    @media screen and (device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)  
    
    //iPhone 4
    @media screen and (device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)  
    
    //iPhone 5
    
    @media screen and (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)  
    
    //iPhone 6
    @media screen and (device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)  
    
    //iPhone 6 Plus
    @media screen and (device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3)  
    
    //Huawei Ascend P6
    @media screen and (device-width: 360px) and (device-height: 592px) and (-webkit-device-pixel-ratio: 2)  
    
    0 讨论(0)
  • 2021-02-04 23:42

    Try with below media query and meta tag

    /* For mobile : like samsung grand(480 * 800): */
    @media screen and (max-width : 480px){}
    
    
    /* For iphone: */
    @media screen and (max-width : 320px){} 
    
    
    /* For ipad: */
    @media screen and (max-width : 768px){} 
    

    Additionally. change your meta tag:

    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    
    0 讨论(0)
提交回复
热议问题