2015-02-24 88 views
-2

我有一个基于wordpress和响应式设计“Mystile”的网站。HTML:停止移动视图上的重叠图片(响应式设计)

我用下面的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> 

这完美的作品在计算机上。 正如你所看到的图片。

enter image description here

但在移动设备上,它看起来可怕。 像这样:

enter image description here

什么可以应该怎么办? 非常感谢。

+1

如果你想要一个“响应式设计”,不要使用绝对位置或固定'px'值作为这样的保证金。 – DaniP 2015-02-24 13:27:06

+0

[** http://learnlayout.com/**](http://learnlayout.com/) – 2015-02-24 13:29:05

+0

好的。我的wordpress主题会自动制作响应式设计。我的代码应该如何在电脑和移动视图上运行?谢谢。 – zander 2015-02-24 13:29:06

回答

0

最简单的就是直接显示图像。然后,他们将在互相缠绕,如果没有足够的空间,以适应彼此的旁边:

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


如果你想获得更先进一点,你可以使用 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; 
 
    } 
 
}
<div class="hmm"><a href="myhref"><img src="http://www.placehold.it/240x50" alt="placeholder" /></a><a href="myhref"><img src="http://www.placehold.it/240x50" alt="placeholder" /></a><a href="myhref"><img src="http://www.placehold.it/240x50" alt="placeholder" /></a></div>

^去'整页'和调整大小,看看这个工作。

+0

太好了,谢谢!这工作完美。你能告诉我在哪里可以定义图片之间的距离吗? – zander 2015-02-24 14:21:40

+0

是的,只需更改“边距”即可。你会看到我已经给他们一个10px的顶部和左边距。 – Moob 2015-02-24 14:29:49