@Media 最小宽度 &最大宽度 [英] @Media min-width & max-width

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

问题描述

我有这个 @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 */
}

通过此设置,它可以在 iPhone 上运行,但不能在浏览器中运行.

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

是不是因为我在元数据中已经有了 device,也许还有 max-width:480px ?

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

推荐答案

我发现最好的方法是为旧版浏览器编写默认 CSS,因为旧版浏览器(包括 IE 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 IE 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 最小宽度 &amp;最大宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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