CSS media queries for iPhone

前端 未结 2 1970
小鲜肉
小鲜肉 2021-01-07 05:30

I have a website that will be displayed on both the desktop and on an iPhone using media queries to serve different stylesheets so for example ALWAYS load reset.css, but if

相关标签:
2条回答
  • 2021-01-07 05:51

    Your @import must come before all other content in your CSS.

    If you want just 1 CSS file in the HTML, why not copy and paste all those imports and paste them where you're trying to call the imports, ie.

    // css for reset.css
    
    @media only screen and (min-device-width: 320px) and (max-device-width: 480px)
    {
        // css for desktop
    }
    ...
    
    0 讨论(0)
  • 2021-01-07 06:01

    Why don't you use css for desktop as inline, and override it with css for iphone? Moreover, desktops are much wider than these dimensions - (min-device-width: 320px) and (max-device-width: 480px). (min-device-width: 320px) and (max-device-width: 480px) are dimensions of an iphone/smartphones (most of them atleast). Hence, the code should be:

    @import "reset.css";
    
    @media only screen and (min-device-width: 320px) and (max-device-width: 480px)
    {
    @import "iphone.css";
    }
    
    //1024px - max width of an ipad, min-device-aspect-ratio - detects desktop
    @media all and (min-width: 1024px) and (min-device-aspect-ratio: 1/1)
    {
    @import "desktop.css";
    }
    
    0 讨论(0)
提交回复
热议问题