浏览器无法识别最大设备宽度 [英] Browser not recognizing max-device-width

查看:285
本文介绍了浏览器无法识别最大设备宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的网站执行自适应网页设计。为此,我使用@media查询
在不同的设备上显示不同的视图。为了测试目的,我使用web开发人员
工具栏的firefox和响应式网站视图加载项谷歌chrome。

I am implementing responsive web design for my site. For that I am using @media queries for displaying different views on different devices. For testing purpose I am using web developer toolbar for firefox and responsive site view add-on for google chrome.

但是如果我使用:

@media only screen and (max-device-width: 480px)
{
    //CSS
}

然后它在实际设备上运行,但不在浏览器中

Then its working on actual device but not in browser

如果我使用

@media only screen and (max-width: 480px)
{
    //CSS
}

那么它只能在浏览器上工作,而不是在设备上。

Then its only working on browser and not in device.

我在哪里错了?需要帮助

Where I am going wrong? Need Help

推荐答案

在您的情况下,您可以像这样使用

In your case you can use like this

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

这是一个诽谤的媒体查询代码,所有设备的 Chris Coyier

and this is a slandered media queries code for all devices by Chris Coyier

/* Smartphones (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen 
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen 
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}

/* Desktops and laptops ----------- */
@media only screen 
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen 
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}

这篇关于浏览器无法识别最大设备宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆