android - 媒体查询适用于桌面但不适用于移动设备

标签 android html css media-queries

我知道这个问题已经被问过很多次了,但我找到的答案并没有帮助。 我的媒体查询在桌面上运行得很好,但在 3 种不同的 Android 设备上却不行。没有任何变化,就好像 MQ 不存在一样。 我尝试使用全部,屏幕,仅屏幕。基本上所有选项,将我的元标记更改为您在下面看到的内容。

元:

 <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1" name="viewport">
        <link rel="stylesheet" href="style_mini.css">

@media handheld, screen and (max-width: 48em) { some style }

这是我的第一个网站,我真的不知道自己做错了什么。

好吧,所以我花了几个小时进行测试,我的两个设备都“认为”它们有 960px,并针对这个宽度使用媒体查询,而不是使用更小的 MQ。 此处建议的操作:http://webdesign.tutsplus.com/articles/quick-tip-dont-forget-the-viewport-meta-tag--webdesign-5972没有帮助。

html {} 
* {
 box-sizing: border-box;
 -moz-box-sizing: border-box;
 -webkit-box-sizing: border-box;
 -webkit-text-size-adjust:none;
 }
 body {
 font-family: 'Slabo 27px', serif;
 color: #3F4D59;
 background-color: #F2E9DE;
 width: 98%;
 margin: 0 auto;
}
.flex {
 display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: center;
align-content: center;
align-items: center;
}
.top {
flex-direction: row;
order: 1;
background-color: #F2E9DE;
justify-content: left;
align-content: left;
align-items: left;
}
.top {
width: 100%;
position: fixed;
top: 0px;
z-index: 1000;
margin: auto;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=92);
-moz-opacity: 0.92;
-khtml-opacity: 0.92;
opacity: 0.92;
}
.anchor {
display: block;
height: 200px;
/*same height as header*/

margin-top: -200px;
/*same height as header*/

visibility: hidden;
}
.content {
padding-top: 200px;
}
.header {
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
align-self: auto;
/*    min-width: 0;*/

min-height: auto;
width: 35%;
text-align: center;
font-size: 3em;
padding: 2%;
} 
.nav {
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
align-self: auto;
/*    min-width: 0;*/

min-height: auto;
width: 50%;
font-size: 2.5em;
text-align: right;
}
.nav a {
padding: 3%;
}
a:link,
a:visited {
color: #3F4D59;
text-decoration: none;
font-weight: bolder;
}
a:hover {
color: #9CA1A6;
text-decoration: none;
}
.stamp {
width: 15%;
}
.stamp {
background: url(images/kowalew_ALL.jpg);
display: block;
height: 200px;
width: 200px;
background-repeat: no-repeat;
/*    text-indent: -9999px;*/
}
.stamp:hover {
background-position: 0 -200px;
}
.offer {
order: 4;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
align-self: auto;
min-width: 0;
min-height: auto;
padding-top: 3%;
padding-bottom: 4%;
padding-left: 2%;
background-image: url(images/pea3.jpg);
background-repeat: no-repeat;
background-size: cover;
}
h1 {
font-size: 2em;
color: #3F4D59;
} 
li {
font-size: 1.4em;
font-weight: 600;
text-align: left;
color: #F2E9DE;
}
.mini-contact {
order: 5;
background-color: #9ca1a6;
flex-direction: row;
}
.mini-contact p {
padding: 0 5%;
font-size: 1.2em;
}
.nolist {
list-style-type: none;
 }
.sectionheader {
text-align: center;
font-size: 2.5em;
font-weight: 800;
flex-direction: column;
background-color: #F2E9DE;
}
.subsectionheader {
text-align: center;
font-size: 1.8em;
background-color: #F2E9DE;
}
.gallery {
flex-direction: row;
background-color: #F2E9DE;
}
.gallery img {
 width: 20%;
 margin: 0.1%;
 border: solid 4px #3F4D59;
 }
.videocontainer iframe {
 position: absolute;
 top: 0;
 left: 0;
 width: 100%;
 height: 100%;
 border: solid 4px #3F4D59;
 }
.gallery img:hover {
 position: relative;
 overflow-x: hidden;
 border-radius: 10px;
 margin: auto 0;
 box-shadow: 7px 7px 10px #9ca1a6;
 transition: 0.5s ease-in-out;
 z-index: 2000;
 }
.right:hover {
transform: scale(2) translateX(-25%);
}
.left:hover {
transform: scale(2) translateX(25%);
}
.middle:hover {
transform: scale(2);
}
.videocontainer a img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: solid 4px #3F4D59;
}
.video {
flex-direction: row;
}
.videocontainer {
position: relative;
padding-bottom: 10%;
padding-top: 135px;
margin-right: 2%;
margin-left: 2%;
height: 0;
overflow: hidden;
flex-direction: column;
width: 33%;
order: 1
}
.caption {
flex-direction: row;
width: 100%;
padding: 0;
}
.caption p {
width: 33%;
padding: 0;
}
.backgroundcon {
background-color: #9ca1a6;
padding-bottom: 4%;
}
.con {
background-color: #9ca1a6;
}
.contact p {
font-size: 1.4em;
font-weight: 700;
 }
.map {
border: solid 3px #3F4D59;
 }
footer {
text-align: center;
padding-top: 3%;
padding-bottom: 2%;
}
/*MEDIA QUARIES*/

@media handheld, screen and (max-width: 85.375em) {
.hide {
    display: none;
}
}
@media handheld, screen and (max-width: 64em) {
.header {
    font-size: 2em;
 }
.nav {
    font-size: 1.8em;
 }
.subsectionheader {
    font-size: 1.3em;
 }
.sectionheader {
    font-size: 2em;
    font-weight: 300;
 }
 }
 @media handheld, screen and (max-width: 48em) {
 .shide {
    display: none;
 }
 .gallery img {
    width: 25%;
 }
 .contact p {
    font-size: 1.1em;
    font-weight: 300;
 }
.sectionheader {
    font-size: 1.8em;
}
.nav {
    width: 60%;
}
.header {
    width: 40%;
}
.content {
    padding-top: 130px;
}
}
@media handheld, screen and (max-width: 40em) {
.xshide {
    display: none;
}
.gallery img {
    width: 33%;
}
.top {
    flex-direction: column;
}
.header {
    flex-direction: row;
    width: 100%;
    text-align: center;
}
.nav {
    flex-direction: row;
    width: 100%;
    text-align: center;
}
.content {
    padding-top: 130px;
}
}
@media handheld, screen and (max-width: 30em) {
.xxshide {
    display: none;
}
.gallery img {
    width: 50%;
}
.offer {
    background-image: none;
    margin-top: 2px;
}
a:hover {
    color: #498099;
    text-decoration: none;
}
li {
    color: #3F4D59;
}
.top {
    background-color: #9ca1a6;
    box-shadow: 3px 3px 3px #a7a4a4;
    border: solid 1px #a7a4a4;
    border-radius: 5px;
}
.mini-contact {
    box-shadow: 3px 3px 3px #a7a4a4;
    border: solid 1px #a7a4a4;
    border-radius: 5px;
}
.nav a {
    padding-bottom: 3%;
}
.backgroundcon {
    box-shadow: 3px 3px 3px #a7a4a4;
    border: solid 1px #a7a4a4;
    border-radius: 5px;
}
.caption p {
    width: 50%;
}
.videocontainer {
    width: 50%;
}
.content {
    padding-top: 80px;
}
 }
@media handheld, screen and (max-width: 20em) {
.nav {
    flex-direction: column;
    width: auto;
}
.top {
    flex-direction: column;
}
.xxxshide {
    display: none;
}
li {
    font-size: 1.1em;
}
h1 {
    font-size: 1.5em;
}
footer {
    font-size: .8em;
}
}

最佳答案

尝试替换最大尺寸的单位:使用px代替em

这是我一直用于媒体查询的代码示例,它始终适用于移动设备:

@media screen and (max-width : 1024px) {
    /* Change 1024 by what you need. */
}

这是 W3schools em 单位的描述:

Relative to the font-size of the element (2em means 2 times the size of the current font)

根据文档的字体大小定义媒体查询有点奇怪!

关于android - 媒体查询适用于桌面但不适用于移动设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32694684/

相关文章:

android - 如何区分 facebook API 中的 "tag"和 "post on wall"操作

android - 在带有标题的操作栏上创建抽屉导航

html - 如何解决在 ubuntu apache2 上使用 mod_jk 和虚拟主机重定向到 tomcat 时添加自定义错误 503 页面 html

javascript - 使用 <br> 提取段落的第 n 行

javascript - jquery 可拖动元素 - 移动设备中的小移动 - 防止 onclick 触发

android - 如何在android项目的res文件夹中获取图像的像素

html - 使子溢出 div 正确调整其父级的大小

css - 如何在CSS中设置父子之间的边界?

html - 如何使浏览器窗口的高度为100%

Android MediaRecorder Stop() 函数给出错误 E/MediaRecorder : stop failed: -1007