【发布时间】:2015-06-21 13:17:07
【问题描述】:
我正在尝试在网站的桌面版本上隐藏一个 div 元素并将其显示在移动设备上。但是使用媒体查询不允许我。您知道可能导致问题的原因吗?以下是我的代码:
@media all and(min-device-width: 768px){
.Products{display:block;}
.Products-Mobile{display:none;}
.Benefits{ display:block;}
}
@media all and(min-device-width: 321px) and (max-device-width: 767px){
.Products{display:block;}
.Products-Mobile{display:none;}
.Benefits{ display:block;}
}
@media all and(max-device-width: 320px){
.Products{display:none;}
.Products-Mobile{display:block;}
.Benefits{ display:block;}
}
还有我的html:
<!-- This class will be displayed on the desktop version of the site and will be hidden on the mobile -->
<div class="Products">
Desktop test
</div>
<!-- This class will be displayed on the desktop version of the site and will be hidden on the mobile -->
<div class="Products-Mobile">this is mobile test</div>
<!-- This class will be displayed on the mobile and the desktop version of the site -->
<div cass="Benefits">
content
</div>
【问题讨论】:
-
你是在媒体查询之上还是之下指定主css?如果您的媒体查询生效和/或被覆盖,请检查控制台
标签: html css responsive-design media-queries