How to detect ONLY with CSS mobile screens

二次信任 提交于 2019-11-29 07:55:11
Virgil de Meijer

The @media rule is used to define different style rules for different media types/devices.

If it doesnt work, check your code. you might have made a typo somewere.

Example:

@media only screen and (max-device-width : 640px) {
/* Styles */
}

@media only screen and (max-device-width: 768px) {
/* Styles */
}

Earlyer post: How to code CSS media queries targeting ALL mobile devices and tablets?

W3schools: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

CSS media query works, but what about ipads with big screens? You can do the following with javascript:

if (window.orientation !== undefined) {
  document.body.classList.add("mobile");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!