Ans*_*ain 5 html css media-queries
我正在为 Gmail 应用程序创建一个 html 模板。在我添加了一张图片,它应该在桌面视图中占 60%,在移动 gmail 应用程序视图中占 100%。
这是 img 标签宽度 60%:
<div>
<img src="show.jpg" alt="Show your skills" class="mob-img" border="0"
style="outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;
width:60%;" />
</div>
Run Code Online (Sandbox Code Playgroud)
在媒体查询中,我做到了 100%。但它在 gmail 应用程序中不起作用。
@media only screen and (max-width: 600px) {
.mob-img {
width: 100% !important;
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这在 gmail 应用程序中不起作用。如果我遗漏了什么,请告诉我。
提前致谢
问题是:Gmail 应用程序不是“屏幕”媒体。
@media (max-width: 600px) {
.mob-img {
width: 100% !important;
}
}
Run Code Online (Sandbox Code Playgroud)
这个解决方案对我有用。
编辑: Gmail 忽略其他媒体查询。将与 Gmail 应用程序相关的媒体查询移至尽可能的最高点。
在 html 标题中添加元数据
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Run Code Online (Sandbox Code Playgroud)