【问题标题】:CSS rule for tablets and mobiles only, and not desktop?仅适用于平板电脑和手机的 CSS 规则,而不适用于台式机?
【发布时间】:2020-05-02 22:55:33
【问题描述】:

如何制定仅适用于平板电脑和手机(而非台式机)的 CSS 规则? 如果我使用:

@media screen and (max-width: 1400px)

“screen”表示“浏览器窗口”,而不是“设备屏幕”。因此,如果我在桌面上缩小浏览器窗口,将应用此 CSS 规则。

我看到 @media 手持设备 已被弃用。

@media screen and (max-device-width: 1400px)

工作正常,但 device-width 似乎也被弃用了,根据:https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries

【问题讨论】:

  • 你应该使用max-width。视口的宽度是需要更改布局的主要因素。
  • CSS 规则基于 min-widthmax-width 将在用户缩小浏览器窗口时应用。我正在搜索仅适用于不可调整大小的浏览器(平板电脑和智能手机)的 CSS 规则。例如,如果我编写了一条规则来缩放小型设备上的字体,我不希望在用户缩小其桌面上的浏览器窗口时应用此规则。

标签: css responsive


【解决方案1】:

/* 
  ##Device = Desktops
  ##Screen = 1281px to higher resolution desktops
*/

@media (min-width: 1281px) {

  //CSS

}

/* 
  ##Device = Laptops, Desktops
  ##Screen = B/w 1025px to 1280px
*/

@media (min-width: 1025px) and (max-width: 1280px) {

  //CSS

}

/* 
  ##Device = Tablets, Ipads (portrait)
  ##Screen = B/w 768px to 1024px
*/

@media (min-width: 768px) and (max-width: 1024px) {

  //CSS

}

/* 
  ##Device = Tablets, Ipads (landscape)
  ##Screen = B/w 768px to 1024px
*/

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {

  //CSS

}

/* 
  ##Device = Low Resolution Tablets, Mobiles (Landscape)
  ##Screen = B/w 481px to 767px
*/

@media (min-width: 481px) and (max-width: 767px) {

  //CSS

}

/* 
  ##Device = Most of the Smartphones Mobiles (Portrait)
  ##Screen = B/w 320px to 479px
*/

@media (min-width: 320px) and (max-width: 480px) {

  //CSS

}


https://gist.github.com/gokulkrishh/242e68d1ee94ad05f488

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    相关资源
    最近更新 更多