简体   繁体   English

CSS媒体查询不适用于Android设备

[英]CSS Media Queries not Working for Android Device

After searching through related questions, I'm still unable to get media queries to work for my site (in progress): 在搜索了相关问题之后,我仍然无法使媒体查询适合我的网站(进行中):

http://codemusings.net/ http://codemusings.net/

I first ensured that my site validates as valid HTML5. 我首先确保我的网站验证为有效的HTML5。 I'm also using the <meta> tag with name="viewport" : 我还使用<meta>标签和name="viewport"

<meta name="viewport" content="width=device-width,initial-scale=1">

Using help from related questions here, I went to http://mediaqueriestest.com/ , which reports my Samsung Galaxy S4 as having a device-width of 640px . 使用此处相关问题的帮助,我转到了http://mediaqueriestest.com/ ,该站点报告我的Samsung Galaxy S4 device-width640px

I'm using a separate style sheet in which to overwrite style rules in the main style sheet. 我正在使用一个单独的样式表,其中将覆盖主样式表中的样式规则。

<link rel='stylesheet' type='text/css' href='style/main.css'>
<link rel='stylesheet' type='text/css' href='style/mobile.css' media='only screen and (device-width: 640px)'>

Inside mobile.css : mobile.css内部:

nav {
  float: none;
  width: 50%;
}
main {
  float: none;
  width: 90%;
}
.section {
  background: none;
}

To ensure that the problem wasn't with clients fetching the style sheets in the wrong order, I tried appending a media query to my main CSS style sheet: 为了确保问题不在于客户端以错误的顺序获取样式表,我尝试将媒体查询附加到我的主要CSS样式表中:

@media screen only and (device-width: 640px) {
  html { color: red; }
}

However, this didn't work either. 但是,这也不起作用。 I've been specifying device-width: 640px in an attempt to just ensure my mobile CSS works right, but my overall goal is to reliably load different CSS for all smart phones and tablets. 我一直在指定device-width: 640px ,以确保我的移动CSS正常工作,但是我的总体目标是为所有智能手机和平板电脑可靠地加载不同的CSS。

I should also note I'm using Chrome on my Galaxy S4. 我还应该注意,我在Galaxy S4上使用的是Chrome。

try with i think this should work 试试我认为这应该工作

@media only screen and (max-device-width: 640px) {
  html { color: red; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM