大家好,我正在使用多种平板设备,iPad、Galaxy Tab、Acer Iconia、LG 3D Pad等等.

  • iPad-1024 x 768
  • LG Pad-1280 x 768
  • Galaxy选项卡-1280 x 800

我想只针对iPad使用CSS3媒体查询.由于LG和iPad的设备宽度相同,768px-我很难将每个设备分开.

我试着用下面的方法分开,但似乎行不通:

@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation : portrait) /* applied to lg also */
@media only screen and (min-resolution: 132dpi) and (max-device-width: 1024px) and (orientation : portrait) /* applies to lg also */
@media only screen and (device-aspect-ratio: 1024/768) and (orientation : portrait) /* does not work on iPad or LG */

我不知道iPad的-webkit-device-Pixel-Ratio和其他-webkit*选项以及它们的价值.我不想用JavaScript做样式,你有什么 idea 吗?

推荐答案

最终从:Detect different device platforms using CSS找到解决方案

<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait)" href="ipad-portrait.css" />
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape)" href="ipad-landscape.css" />

为了减少HTTP调用,这也可以在现有的公共CSS文件中使用:

@media all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait) {
  .ipad-portrait { color: red; } /* your css rules for ipad portrait */
}
@media all and (device-width: 1024px) and (device-height: 768px) and (orientation:landscape) {
  .ipad-landscape { color: blue; } /* your css rules for ipad landscape */
}

希望这能帮上忙.

其他参考文献:

Css相关问答推荐

如何仅以WooCommerce单一产品页面为目标?

无限交替css动画之间的未知延迟

设置ScaleImageButton的样式

使用文本溢出约束内部 div:没有最大宽度的省略号(或类似的)

使用CSS Grid是否可以跳过下一列?

Tailwind CSS: Select 单选按钮时不应用同行判断的边框

如何更改导航栏标题中链接的文本 colored颜色 和导航丸中的链接(在shiny 的应用程序中)?

如何使代码块输出在 quarto revealjs 演示文稿中水平滚动

Angular 以Angular 获取当前聚焦的元素

CSS 仅过渡背景 colored颜色

网格在行方向上的大小不正确

如何在 Angular 中使用 CSS 设置 FontAwesome 图标的大小?

使用 CSS 无限期地闪烁两个不同持续时间的文本

弹簧靴.一个文件捕获 CSS 其他没有

水平列表项

有没有办法让字段集的宽度与它们中的控件一样宽?

Bootstrap 3 Glyphicons CDN

CSS 悬停与 JavaScript 鼠标悬停

通过 Bootstrap4 对列进行排序

将 -moz-available 和 -webkit-fill-available 放在一个宽度中(CSS 属性)