【发布时间】:2017-08-17 16:16:33
【问题描述】:
在学习移动优先设计之前,我已经设计了一个网页。
在创建响应式设计时,我创建了 3 个类:.mobile、.tablet、.desktop。
我在导航栏中调用了所有这些类,但在首先为移动设备设计时显然不需要调用我的移动查询(我明白为什么)。每当我删除我的 .mobile 类时,它都会显示移动信息,然后当我将窗口重新调整为更大的窗口时,移动信息会保留,然后添加平板电脑/桌面信息。我将如何正确地重新设计这个? 这是我调整窗口大小时工作形式的主要内容。
/*Mobile Query*/
@media only screen and (max-width:480px) {
.mobile {
display: block;
}
.desktop,
.tablet {
display: none;
}
}
/*Tablet Query*/
@media only screen and (min-width: 481px) and (max-width:768px) {
.tablet {
display: block;
}
.mobile,
.desktop {
display: none;
}
}
/*Desktop Query*/
@media only screen and (min-width: 769px) {
.desktop {
display: block;
}
.mobile,
.tablet {
display: none;
}
}
<h2 class="mobile">About Me</h2>
<p class="mobile">I will not disappoint and I will perform to the best of my ability.</p>
<h2 class="tablet">About Me</h2>
<p class="tablet"> I am somebody who tries their best not to disappoint. I fear that my disappointment will reflect poorly upon myself and people who are close to me. This is something that motivates me to work hard and not to complain. Currently, I work part-time at a
grocery store, run a side business, and go to school more than full time.</p>
</article>
<h2 class="desktop">Strengths</h2>
<p class="desktop">One of my strengths include being very talented at learning or developing new ways to complete objectives. I always enjoy learning about different perspectives, and I believe it is needed to be successful. Another one of my strengths is the ability to
see an error and immediately want to correct it rather than ignoring it and leaving somebody else to fix it. I am driven to be the best at anything I do while wanting to help other people and make their jobs easier.</p>
【问题讨论】:
-
但是您的三个块是相同的html ...我认为您没有理解媒体查询的意义。或者这只是一个可怕的例子?关键是要在不同的屏幕尺寸下更改同一元素的 CSS,只有少数情况需要显示/隐藏特定的块
-
为什么要在任何视口大小上隐藏所有这些内容?对用户来说似乎相当有价值。您没有数英里的内容。
-
这不是桌面视口的全部信息
-
我想你误解了,即使你有更多的桌面内容,你为什么要制作这些不同的版本?似乎有很多有价值的信息将在桌面级别共享,而在移动级别共享的价值很少。我会在所有级别提供相同的内容,除非我有非常好的理由不这样做。我只是问,你为什么要采取这种方法?背后的原因是什么?
-
无论如何,如果你从一个元素中删除
.mobile,它总是可见的。所以我希望它在所有屏幕尺寸下都可见。就目前而言,您的代码有效。内容仅以适当的屏幕尺寸出现。最后,您的问题不清楚且难以解读目标是什么。