html - 在没有绝对位置的情况下将图像元素堆叠在一起?

标签 html css css-position

所以我有一个场景,我想将图像堆叠在一起以进行幻灯片放映。然而,上下文有点复杂,所以简单地使用 position: absolute 来堆叠它们会把一切都搞砸。不确定我在这里是否有任何选择。

DEMO

<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;
}

最佳答案

我想如果你给类为 .content 的 div 宽度假设为 200px(或图像的宽度),将会起作用,因为图像没有足够的空间来向右走,这样他们就会走到上面那个下面。

示例 here .

关于html - 在没有绝对位置的情况下将图像元素堆叠在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25980230/

相关文章:

javascript - 覆盖自动生成的图标

html - 在 paypal 下拉列表中添加超过 10 行

css - 如何在 kendo ui 中为两个不同的 ListView 设置两种不同的颜色,

css - Position Fixed Child Restricted By Position Relative 父容器的 Z-index

gwt - 如何在 UiBinder XML 文件中使用 AbsolutePanel

css - 模式覆盖和绝对定位元素中的滚动条

html - Bootstrap 导航栏响应 Logo

php - 根据一次搜索查询两个表

css - 如何将媒体查询仅应用于特定宽度范围

javascript - 如何使用 Javascript 或 JQuery 更改 HTML IFrame 元素属性