@Media min-width& max-width [英] @Media min-width & max-width

查看:346
本文介绍了@Media min-width& max-width的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 @media 设置:

HTML

<head>
  <meta name="viewport" content="width=device-width, user-scalable=no" />
</head>

CSS

@media screen and (min-width: 769px) {
    /* STYLES HERE */
}

@media screen and (min-device-width: 481px) and (max-device-width: 768px) { 
    /* STYLES HERE */
}

@media only screen and (max-device-width: 480px) {
    /* STYLES HERE */
}



With this setup it works on the iPhone but it does not work in the browser.

这是因为我已经有设备

Is it because I already have device in the meta, and maybe have max-width:480px instead?

推荐答案

我发现最好的方法是为旧的浏览器编写默认的CSS,如旧的浏览器,包括5.5,6,7和8.无法读取@media。当我使用@media我使用它像这样:

I've found the best method is to write your default CSS for the older browsers, as older browsers including i.e. 5.5, 6, 7 and 8. Can't read @media. When I use @media I use it like this:

<style type="text/css">
    /* default styles here for older browsers. 
       I tend to go for a 600px - 960px width max but using percentages
    */
    @media only screen and (min-width:960px){
        /* styles for browsers larger than 960px; */
    }
    @media only screen and (min-width:1440px){
        /* styles for browsers larger than 1440px; */
    }
    @media only screen and (min-width:2000px){
        /* for sumo sized (mac) screens */
    }
    @media only screen and (max-device-width:480px){
       /* styles for mobile browsers smaller than 480px; (iPhone) */
    }
    @media only screen and (device-width:768px){
       /* default iPad screens */
    }
    /* different techniques for iPad screening */
    @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
      /* For portrait layouts only */
    }

    @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
      /* For landscape layouts only */
    }
</style>

但你可以做任何你喜欢的@media,这只是一个例子,

But you can do whatever you like with your @media, This is just an example of what I've found best for me when building styles for all browsers.

iPad CSS规格。

此外!如果您正在寻找可打印性,可以使用 @media print {}

Also! If you're looking for printability you can use @media print{}

这篇关于@Media min-width&amp; max-width的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆