【问题标题】:display none on desktop / mobile在桌面/移动设备上不显示
【发布时间】:2017-10-03 18:29:38
【问题描述】:

我不确定这里出了什么问题,我正在画一个空白。

我有 2 张桌子。我想向桌面用户显示一个,向移动用户显示一个, 所以我试图设置一个显示没有这是我的代码。

.mobile{display: none;}

这是桌面上移动桌子旁边的 css

@media only screen and (min-width : 320px) {
.desktop{display: none;}
.mobile{ display:block;}}

这是在移动设备上隐藏桌面表格的代码。

这里是html

<table class="desktop">
 <tr>
  <td><img src="images/aqu-landing_icon-win.png"></td>
  <td><img src="images/aqu-landing_icon-mac.png"></td>
  <td><img src="images/aqu-landing_icon-and.png"></td>
  <td><img src="images/aqu-landing_icon-ios.png"></td>
 </tr>
 <tr>
  <td>Windows PC</td>
  <td>Apple PC</td>
  <td>Android Device</td>
  <td>iOS Device</td>
 </tr>
</table>
<table class="mobile">
 <tr>
  <td><img src="images/aqu-landing_icon-and2.png"></td>
  <td><img src="images/aqu-landing_icon-ios2.png"></td>
 </tr>
 <tr>
  <td>Android Device</td>
  <td>iOS Device</td>
 </tr>
</table>

应该像我一样工作吗?

【问题讨论】:

  • 不,你还没有为你的手机设置一个上部宽度,你还没有将相反的样式设置为默认值
  • 使用最大宽度而不是最小宽度
  • 实现其他人的答案,你应该没问题 - 为比 iPhone 4 更大的手机设置大约 425 的最大宽度,并记住这是标题

标签: html css mobile


【解决方案1】:
@media only screen and (min-width : 320px)

表示:适用于具有屏幕且最小宽度为 320 像素的设备。所以这将影响所有超过 320px 的宽度。

要给手机地址,你应该使用max-width

.mobile { display: none; }

@media only screen and (max-width : 320px) {
   .desktop{ display: none; }
   .mobile{ display:block; }
}

还要确保媒体查询在第一行之后...否则它将覆盖它。

【讨论】:

  • 大型手机在 css 方面的宽度约为 425 px - 所以你也许也应该去那里
【解决方案2】:

只要改变你的风格,

min-width : 320px

进入

max-width : 320px

它正在工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2016-04-04
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    相关资源
    最近更新 更多