【发布时间】:2017-03-07 09:14:26
【问题描述】:
以上是我的问题的 CSS。
我的 CSS 是否不正确,每个屏幕尺寸只显示一个类?
我已经做了一百万种不同的变体(当然,这是夸大其词),但我总是得到略有不同但不正确的结果。
这次我最终显示了所有 3 个类,直到屏幕达到 480 像素。
然后只显示了我的.desktop 课程。
/*Desktop Query*/
@media only screen and (min-width: 768px) {
.desktop {
display: none;
}
.mobile, .tablet {
display: block;
}
}
/*Mobile Query*/
@media only screen and (max-width:480px) {
.mobile {
display: none;
}
.desktop, .tablet {
display: block;
}
}
/*Tablet Query*/
@media only screen and (min-width: 481px) and (max-width:768px) {
.tablet {
display: none;
}
.mobile, .desktop {
display: block;
}
}
这是我的 HTML:
<div class="mobile">
<main>
<h2> </h2>
<p> </p>
</main>
</div>
【问题讨论】:
-
这是我所有 3 个 html 的格式点(另外 2 个是 class="desktop" 和 class="tablet") 抱歉,额外的评论和它的格式,在帖子中包含 HTML 代码时遇到问题。