简体   繁体   English

如何将多个图像直接叠加在一起?

[英]How to stack multiple images directly on top of each other?

I am trying to create an interactive filtered map. 我正在尝试创建一个交互式过滤的地图。 Basically I have a background image and some different checkboxes that result in the appearance of images. 基本上我有一个背景图像和一些不同的复选框,导致图像的外观。 If you only tick one checkbox, it works fine - the image just appears over the background image. 如果您只勾选一个复选框,则它可以正常工作 - 图像只显示在背景图像上。 However, if you check multiple images, the other image filters I have set just appear below whatever filter image was checked first. 但是,如果您检查多个图像,我设置的其他图像过滤器只会出现在首先检查的任何过滤器图像下方。 Ideally, the images can overlay on top of each other so they are all seen juxtaposed over the map at once. 理想情况下,图像可以叠加在彼此之上,因此它们可以立即在地图上并列显示。

I apologize if this isn't clear - I am brand new to coding. 如果不清楚,我道歉 - 我对编码很陌生。 Here is the jsfiddle so you can see what I'm talking about: http://jsfiddle.net/klgraywill/Ddnuh/851/ 这是jsfiddle所以你可以看到我在说什么: http//jsfiddle.net/klgraywill/Ddnuh/851/

 <ul class="results">
    <li class="spaces"><div style="position:absolute top: 0px; left: 100px"><img src="http://i.imgur.com/hh0IBC2.png" style="width:804px;height:356px"/></div></li>
    <li class="elements"><div style="position:absolute top: 0px; left: 100px"><img src="http://i.imgur.com/qsJuERK.png" style="width:804px;height:356px"/></div></li>
    <li class="silence"><img src="http://i.imgur.com/KMsmbvf.png" alt="silence" style="width:804px;height:356px""position: relative; top: 0px; left: 100px"/></li>
    <li class="pollution"><img src="http://i.imgur.com/Wjlj4JI.png" alt="polution" style="width:804px;height:356px""position: relative; top: 0px; left: 100px"/></li>
    <li class="active"><img src="http://i.imgur.com/0AF16WH.png" alt="active" style="width:804px;height:356px""position: relative; top: 0px; left: 100px"/></li>
</ul>

You need to absolute position the li containing the images within the main ul , by also setting the top and left of your li to zero, they will layer above one another. 您需要absolute定位包含主要ul图像的li ,同时将litopleft设置为零,它们将叠加在另一个之上。

Demo Fiddle 演示小提琴

Simply change your CSS to: 只需将您的CSS更改为:

body {
    background-image: url("http://i.imgur.com/6xNRfGi.png");
    background-size: 804px 356px;
    background-repeat: no-repeat;
    background-position: 0px 100px; 
}
.container {
    position: relative;
    width: 100%;
}
ul{
    position:relative; /* <-- anchor child li elements positions relative to this */
}
li{
    position:absolute; /* <--- position allows for 'layering' */
    top:0; /* position should start in the same top left corner of the parent ul*/
    left:0; /* position should start in the same top left corner of the parent ul*/
}

Note that if you have applied a position value to an element other than static , you can also control the layer it appears in relative to its parent by setting the z-index 请注意,如果您已将位置值应用于static以外的元素,则还可以通过设置z-index来控制它相对于其父元素显示的图层

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM