【问题标题】:HTML: Stop pictures from overlap on mobile view (responsive design)HTML:阻止图片在移动视图上重叠(响应式设计)
【发布时间】:2015-02-24 13:25:30
【问题描述】:

我有一个基于 wordpress 和响应式设计“Mystile”的网站。

我用下面的html代码并排显示三张图片:

<div style="position: absolute;"><a href="myhref"><img src="myimgsrc" alt="" /></a></div>
<div style="position: absolute; margin-left: 250px;"><a href="myhref"><img src="myimgsrc" alt="" /></a></div>
<div style="position: absolute; margin-left: 500px;"><a href="myhref"><img src="myimgsrc" alt="" /></a></div>

这可以在计算机上完美运行。 如图所示。

但在移动设备上看起来很糟糕。 像这样:

我该怎么办? 非常感谢。

【问题讨论】:

  • 如果您想要“响应式设计”,请不要使用绝对位置或固定的px 值作为这样的边距。
  • 好的。我的 wordpress 主题会自动进行响应式设计。我的代码应该如何在计算机和移动视图上运行?谢谢。
  • 从响应式和媒体查询的基础入手可没那么简单
  • 您的 wordpress 主题没有响应......简单来说。

标签: html css wordpress mobile


【解决方案1】:

最简单的方法就是内联显示图像。如果没有足够的空间可以并排放置,它们会相互包裹:

html, body {margin:0;}
.hmm a {display:inline-block; margin:10px 0 0 10px;}
.hmm a img {display:block; margin:0;}
&lt;div class="hmm"&gt;&lt;a href="myhref"&gt;&lt;img src="http://www.placehold.it/240x50" alt="placeholder" /&gt;&lt;/a&gt;&lt;a href="myhref"&gt;&lt;img src="http://www.placehold.it/240x50" alt="placeholder" /&gt;&lt;/a&gt;&lt;a href="myhref"&gt;&lt;img src="http://www.placehold.it/240x50" alt="placeholder" /&gt;&lt;/a&gt;&lt;/div&gt;


如果您想更高级一点,可以使用media-queries 更改不同大小视口的样式:

html, body {margin:0;}
.hmm a {display:inline-block; margin:10px 0 0 10px;}
.hmm a img {display:block; margin:0;}

@media all and (max-width: 750px) {
  .hmm a:first-of-type img {width:490px;}
}

@media all and (max-width: 510px) {
  .hmm a {
      display: block;
      margin:10px;
  }    
  .hmm a img {
      width:100%!important;
  }
}
&lt;div class="hmm"&gt;&lt;a href="myhref"&gt;&lt;img src="http://www.placehold.it/240x50" alt="placeholder" /&gt;&lt;/a&gt;&lt;a href="myhref"&gt;&lt;img src="http://www.placehold.it/240x50" alt="placeholder" /&gt;&lt;/a&gt;&lt;a href="myhref"&gt;&lt;img src="http://www.placehold.it/240x50" alt="placeholder" /&gt;&lt;/a&gt;&lt;/div&gt;

^ 转到“整页”并调整大小以查看此内容是否正常工作。

【讨论】:

  • 太好了,谢谢!这很完美。你能告诉我在哪里可以定义图片之间的距离吗?
  • 是的,只需更改margin。你会看到我给了他们一个 10px 的顶部和左边距。
猜你喜欢
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多