是否有一种@media查询可以仅针对运行iOS的设备进行定位?
例如:
@media (min-device-width:320px) and (max-device-width:768px) {
#nav {
yada: yada;
}
}
这是否也会改变在这些设备宽度下的 Android 设备上页面的行为?
是否有一种@media查询可以仅针对运行iOS的设备进行定位?
例如:
@media (min-device-width:320px) and (max-device-width:768px) {
#nav {
yada: yada;
}
}
这是否也会改变在这些设备宽度下的 Android 设备上页面的行为?
可以的。
@supports (-webkit-touch-callout: none) {
/* CSS specific to iOS devices */
}
@supports not (-webkit-touch-callout: none) {
/* CSS for other than iOS devices */
}
各人因素而异。
之所以有效,是因为只有Safari Mobile 实现了-webkit-touch-callout
:https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-touch-callout
请注意,@supports
不适用于 IE。IE 会跳过上述两个 @support
块。欲了解更多信息,请参见https://hacks.mozilla.org/2016/08/using-feature-queries-in-css/。建议不要使用 @supports not
。
那么在 iOS 上的 Chrome 或 Firefox 呢?实际上,它们只是 WebKit 渲染引擎上的皮肤。因此,上述方法在 iOS 的任何地方都适用,只要 iOS 政策没有改变。有关详细信息,请参见App Store Review Guidelines中的 2.5.6。
警告:iOS 可能会在未来几年的新版本中删除对此的支持。您应该尽力避免需要以上的CSS。本答案的早期版本使用了-webkit-overflow-scrolling
,但新的iOS版本将其删除。正如一位评论者指出的那样,还有其他可供选择的选项:转到支持的 CSS 属性并搜索“Safari on iOS”。
我不确定是否针对整个iOS系统,但是要专门针对iOS Safari:
@supports (-webkit-touch-callout: none) {
/* CSS specific to iOS devices */
}
@supports not (-webkit-touch-callout: none) {
/* CSS for other than iOS devices */
}
据称,在iOS 13中,-webkit-overflow-scrolling
不再响应@supports
,但-webkit-touch-callout
仍然响应。当然,这在将来可能会改变...
如上所述,简短的答案是否定的。但是在我现在正在开发的应用程序中,我需要类似的东西,但CSS需要不同的区域仅限于页面的非常特定的部分。
如果您和我一样,并且不需要提供完全不同的样式表,另一个选项是检测运行iOS的设备,方法如此问题中所述的选定答案:Detect if device is iOS
一旦您检测到了iOS设备,就可以使用JavaScript(例如document.getElementsByTagName("yourElementHere")[0].setAttribute("class","iOS-device");
)、jQuery、PHP或其他方式向目标区域添加一个类,并使用现有的样式表相应地设置该类的样式。
.iOS-device {
style-you-want-to-set: yada;
}
简短回答是不需要。CSS并不特定于品牌。
以下是仅使用媒体的iOS实现文章。
https://css-tricks.com/snippets/css/media-queries-for-standard-devices/
http://stephen.io/mediaqueries/
实际上,您可以使用PHP、Javascript来检测iOS浏览器,并根据此调用CSS文件。例如