我正在尝试为智能手机方向和桌面设置不同的媒体查询,我想要定位纵向和横向。我知道所有其他堆栈链接:
Media query to target most of smartphone 3 media queries for iphone portrait, landscape and ipad portrait
但我仍然遇到问题,我的情况不起作用,这是我正在使用的代码:
Desktop css first
-- csss for desk --
Portrait:
@media only screen and (min-device-width: 320px) and (max-device-width: 479px) {
body {
padding: 0 !important;
}
.infoShowWrapper {
width: 268px;
}
.heroImage {
margin-top: 0;
height: 200px;
width: 100%;
background: #fff url(assets/images/hero_small.jpg) no-repeat center center;
}
.navbar-fixed-top {
margin: 0 !important;
}
.box-item {
width: 280px;
}
.seaBkg {
background-image: url(assets/images/mare_2x.jpg);
}
}
Landscape:
@media only screen and (min-device-width: 480px) and (max-device-width: 640px) {
body {
padding: 0 !important;
}
.heroImage {
margin-top: 0;
height: 200px;
width: 100%;
background: #fff url(assets/images/hero_small.jpg) no-repeat center center;
}
.navbar-fixed-top {
margin: 0 !important;
}
.box-item {
width: 440px;
}
.infoShowWrapper {
width: 440px;
}
.seaBkg {
background-image: url(assets/images/mare_2x.jpg);
}
}
景观代码甚至没有被考虑
答案 0 :(得分:23)
尝试添加
orientation : landscape
@media only screen and (min-device-width: 480px)
and (max-device-width: 640px)
and (orientation: landscape) {
//enter code here
}
请参阅this site或 this snippet 以供参考。