[英]Css3 device-width and orientation change
I'd like the background color to change while changing orientation. 我希望背景颜色可以在更改方向时更改。 I have the following code:
我有以下代码:
<meta name="viewport" content="width=device-width">
...
@media all and (max-device-width: 360px) {
div { background-color: green; } }
@media all and (min-device-width: 361px) {
div { background-color: blue; } }
Unfortunately this doesn't work. 不幸的是,这不起作用。 But when i change
max-device-width
and min-device-width
to max-width
and min-width
it works. 但是,当我将
max-device-width
和min-device-width
更改为max-width
和min-width
它可以工作。 Why the code with max-device-width
and min-device-width
isn't working? 为什么具有
max-device-width
和min-device-width
的代码不起作用?
This should work: 这应该工作:
Add this to your HTML Page: 将此添加到您的HTML页面:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
And to your css code you have to add: 在您的CSS代码中,您必须添加:
div {
background-color: blue;
}
@media (max-width: 360px) {
div{
background-color: green;
}
}
So when the window width is under 360 Pixel, the background-color will change to green, otherwise it will be blue. 因此,当窗口宽度小于360像素时,背景颜色将变为绿色,否则将变为蓝色。
Because it has to know that it is a device by displaying it. 因为它必须通过显示它来知道它是一个设备。 So it excludes all desktop visibility.
因此,它排除了所有桌面可见性。
I would recommend not using this because not all device browsers send a recognition that the content is viewed on a device making it unpredictable when your design is applied. 我建议您不要使用此功能,因为并非所有设备浏览器都会发送识别信息,表明您在设备上查看了内容,从而在应用设计时无法预测。
Stick to min-width and height it is saver. 坚持最小宽度和高度是节省者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.