媒体查询和 CSS LESS FRAMEWORK 4
我已经在 less 4 框架中安装了 css 默认值。它们提供根据“浏览器大小”更改正文声明的媒体查询。我添加了声明来更改正文背景颜色,这样当我在桌面上缩放 google chrome 浏览器时,我就可以看到哪个媒体查询正在启动。
默认桌面颜色为白色。然后我有平板电脑布局和移动布局:
/* Tablet Layout: 768px.
Gutters: 24px.
Outer margins: 28px.
Inherits styles from: Default Layout.
-----------------------------------------------------------------
cols 1 2 3 4 5 6 7 8
px 68 160 252 344 436 528 620 712 */
@media only screen and (min-width: 768px) and (max-width: 991px) {
body {
width: 712px;
padding: 10px 20px 60px;
background-color:yellow;
}
}
/* Mobile Layout: 320px.
Gutters: 24px.
Outer margins: 34px.
Inherits styles from: Default Layout.
---------------------------------------------
cols 1 2 3
px 68 160 252 */
@media only screen and (max-width: 767px) {
body {
width: 252px;
padding: 10px 20px 60px;
background-color:pink;
}
}
当我调整桌面浏览器大小时,它会改变颜色。但是当我在 HTC Feeling Android 浏览器中打开页面时,它是黄色的。显然,媒体查询并没有针对我的浏览器的“大小”起作用。我还读到有一种叫做视口的东西,它可能正在缩放我的手机中的页面,使得浏览器分辨率不满足媒体查询阈值。如何解决此问题,以便为我的手机启动正确的媒体查询?
I have installed the css defaults in the less 4 framework. They provide media queries that change the body declaration based on the "browser size". I added declarations to change the body background-color so I can see which media query is kicking in as I scale my google chrome browser on my desktop.
default desktop color is white. Then I have tablet layout and mobile layout as such:
/* Tablet Layout: 768px.
Gutters: 24px.
Outer margins: 28px.
Inherits styles from: Default Layout.
-----------------------------------------------------------------
cols 1 2 3 4 5 6 7 8
px 68 160 252 344 436 528 620 712 */
@media only screen and (min-width: 768px) and (max-width: 991px) {
body {
width: 712px;
padding: 10px 20px 60px;
background-color:yellow;
}
}
/* Mobile Layout: 320px.
Gutters: 24px.
Outer margins: 34px.
Inherits styles from: Default Layout.
---------------------------------------------
cols 1 2 3
px 68 160 252 */
@media only screen and (max-width: 767px) {
body {
width: 252px;
padding: 10px 20px 60px;
background-color:pink;
}
}
It changes color when when I resize my desktop browser. But when I open the page in my HTC sensation android browser, it's yellow. Clearly the media query is not kicking in for my browser's "size". I have also read that there is something called viewport, which perhaps is scaling the page in my mobile phone such that the browser resolution is not meeting the media query threshold. How do I remedy this so that the correct media query kicks in for my mobile phone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用设备宽度作为 iOS 和 Android 的默认设置,然后仅使用 iOS 的方向扩展媒体查询
use device-width as your default for iOS and Android then extend the media query with orientation for iOS only