【问题标题】:How to get rid of spaces on mobile version手机版怎么去掉空格
【发布时间】:2014-07-19 15:23:47
【问题描述】:

目前在我的 style.css 文件中,我仅将某些设计用于我的网站的移动版本。

这里是开始标签:

@media only screen and (min-width : 150px) and (max-width : 780px)

我希望能够对其进行设置,以便当网站在移动设备上时它不使用下面显示的 &nbsp,我只想在完整桌面中使用 &nbsp。有没有办法在 css 文件中处理这个问题?

<td colspan="2" style="font-size: 16pt;">
 <a href="index.php">Home</a> &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; 
 <a href="product_list.php">All Products</a>
</td>

【问题讨论】:

  • 使用边距或内边距代替&amp;nbsp;

标签: html css


【解决方案1】:

如果您想为此使用 CSS。然后在桌面站点上,您必须这样编写 HTML

<td colspan="2" style="font-size: 16pt;">
 <a href="index.php">Home</a>
 <a href="product_list.php" style="margin-left: 10px;">All Products</a>
</td>

&amp;nbsp; 不能使用 CSS 动态删除。 JavaScript 可以处理这些事件,但 CSS 不是为处理这些事件而设计的。

通过这种方式,您可以使用 CSS 控制元素之间的间距。现在在媒体样式中,您可以删除此边距。

@media only screen and (min-width : 150px) and (max-width : 780px) {
   td a:nth-child(2) {
      /* second a */
      margin-left: 0;
   }
}

【讨论】:

  • 感谢它的工作!我会尽可能接受你的回答
【解决方案2】:

我认为有两种可能的解决方案:

  1. 使用边距而不是&amp;nbsp;,因为不间断空格受到保护,无法通过 CSS 删除。您可以将margin:0 3%; 或类似名称应用于锚点。
  2. &amp;nbsp;s 包装成一个跨度:&lt;span class="spacer"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;,并在移动设备上应用 display:none

【讨论】:

    猜你喜欢
    • 2014-11-18
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多