0
所以我有一个场景,我想堆叠图像在彼此的顶部放映幻灯片。但是,上下文有点复杂,所以只需使用position: absolute
来堆叠它们即可解决所有问题。不知道我在这里有什么选择。将图像元素堆叠在一起而没有绝对位置?
<div class="article photo post">
<div class="inner">
<div class="overlay">
<div class="title vertical">Title</div>
</div>
<div class="content slideshow">
<img src="https://dl.dropboxusercontent.com/u/3618143/2-large.jpg" style="max-width: 40vw; display: inline;">
</div>
</div>
</div>
<div class="article photo post">
<div class="inner">
<div class="overlay">
<div class="title vertical">Title</div>
</div>
<div class="content slideshow">
<img src="https://dl.dropboxusercontent.com/u/3618143/1-large.jpg" style="max-width: 40vw; display: inline;">
<img src="https://dl.dropboxusercontent.com/u/3618143/2-large.jpg" style="max-width: 40vw; display: inline;">
<img src="https://dl.dropboxusercontent.com/u/3618143/3-large.jpg" style="max-width: 40vw; display: inline;">
<img src="https://dl.dropboxusercontent.com/u/3618143/4-large.jpg" style="max-width: 40vw; display: inline;">
</div>
</div>
</div>
.article {
position: relative;
float: none;
display: inline-block;
vertical-align: bottom;
padding: 10px;
}
.article .inner {
position: relative;
width: 100%;
height: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-webkit-box-direction: reverse;
-moz-box-direction: reverse;
-webkit-flex-direction: column-reverse;
-ms-flex-direction: column-reverse;
flex-direction: column-reverse;
}
.article .overlay {
position: absolute;
top: -1px;
right: 0;
bottom: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 2;
overflow: hidden;
background-color: rgba(0,0,0,0);
-webkit-transition: background-color .3s ease-out;
-moz-transition: background-color .3s ease-out;
-o-transition: background-color .3s ease-out;
transition: background-color .3s ease-out;
margin: 0 0 -25px;
}
.article .title {
color: rgba(255,255,255,0);
-webkit-transition: color .2s ease-out 0s;
-moz-transition: color .2s ease-out 0s;
-o-transition: color .2s ease-out 0s;
transition: color .2s ease-out 0s;
-webkit-transform: translateZ(0);
}
.article:hover .overlay {
pointer-events: auto;
background-color: rgba(0, 0, 0, 0.7);
-webkit-transition: background-color .3s ease-out .75s;
-moz-transition: background-color .3s ease-out .75s;
-o-transition: background-color .3s ease-out .75s;
transition: background-color .3s ease-out .75s;
}
.article:hover .title {
color: rgba(255, 255, 255, 1);
-webkit-transition: color .5s ease-out .75s;
-moz-transition: color .5s ease-out .75s;
-o-transition: color .5s ease-out .75s;
transition: color .5s ease-out .75s;
}
.vertical {
height: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-webkit-flex-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.content {
position: relative;
}
.content img {
max-height: 70vh;
}
目前还不清楚你想达到什么目的。我的意思是,不管它是什么,它都很容易,但是你的编码与我理解你想达到的内容相矛盾,所以不确定我是否理解正确。此外,您没有任何幻灯片。然后,不管它是什么,都很容易,我已经尝试了几种不同的场景,他们都在工作 – Devin 2014-09-22 18:06:07
@Fabio应该没有固定的宽度或高度。如果您查看第一张图片,您只有元素的宽度(在我的真实场景中随机设置)。没有幻灯片的脚本,因为我首先必须解决如何首先堆叠图像(只需将pos:abs添加到.content中的img元素不起作用)。 – INT 2014-09-22 18:09:33
会发生什么情况是,.content中的img元素被分配了一个随机的vw值,并且设置了整个.article的宽度和高度,让覆盖层扩展到最上面。 – INT 2014-09-22 18:11:37