首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >@媒体最小宽度和最大宽度

@媒体最小宽度和最大宽度
EN

Stack Overflow用户
提问于 2012-11-25 19:20:44
回答 6查看 1.2M关注 0票数 255

我有这个@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上工作,但在浏览器中不能工作。

是不是因为我已经在meta中有了device,也许我已经有了max-width:480px

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2012-11-25 19:47:56

我发现最好的方法是为老的浏览器编写默认的CSS,因为老的浏览器(包括IE5.5,6,7和8)不能读取@media。当我使用@media时,我是这样使用它的:

<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做任何你想做的事情。这只是我在为所有浏览器构建样式时发现的最适合我的一个示例。

iPad CSS specifications.

还有!如果你正在寻找可打印性,你可以使用@media print{}

票数 395
EN

Stack Overflow用户

发布于 2014-07-09 03:24:24

潜在的问题是使用max-device-width与普通的老式max-width

使用"device“关键字的目标是屏幕的物理尺寸,而不是浏览器窗口的宽度。

例如:

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

对比

@media only screen and (max-width: 480px) {
    /* STYLES HERE for BROWSER WINDOWS with a max-width of 480px. 
       This will work on desktops when the window is narrowed.  */
}
票数 43
EN

Stack Overflow用户

发布于 2019-05-02 18:21:25

如果网站在小型设备上运行,如桌面屏幕,则您必须将此元标签放入标题之前

<meta name="viewport" content="width=device-width, initial-scale=1">

对于媒体查询,您可以将其设置为

这将覆盖您的所有移动/手机宽度

 @media only screen and (min-width: 200px) and (max-width: 767px)  {
    //Put your CSS here for 200px to 767px width devices (cover all width between 200px to 767px //
   
    }

对于iPad和iPad pro,您必须使用

  @media only screen and (min-width: 768px) and (max-width: 1024px)  {
        //Put your CSS here for 768px to 1024px width devices(covers all width between 768px to 1024px //   
  }

如果您想为横向模式添加css,可以添加以下内容

和(方向:横向)

  @media only screen and (min-width: 200px) and (max-width: 767px) and (orientation : portrait) {
        //Put your CSS here for 200px to 767px width devices (cover all mobile portrait width //        
  }
票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13550541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档