【发布时间】:2019-05-14 03:07:50
【问题描述】:
考虑以下 DOM 分布。我有一个带有两个孩子的flexbox 容器,其中一个具有固定大小,而另一个则缩小为overflow: hidden。但是,我想知道是否有办法让溢出的内容保持可见而不影响 DOM 的流动。
Fleshed out Example at Codepen
ul.current {
list-style: none;
display: flex;
width: 40%;
margin: 0 auto;
}
li {
overflow: hidden;
}
li:last-child {
flex-shrink: 0;
}
li div {
border: 1px solid black;
background: green;
width: 10rem;
height: 10rem;
}
li:last-child {
margin-top: 2rem;
}
li:last-child div {
background: red;
}
/* GOAL */
section {
margin: 0 auto;
width: 40%;
}
.item {
position: absolute;
}
.item:last-child {
margin-top: 2rem;
margin-left: 5rem;
}
.content {
border: 1px solid black;
background: green;
width: 10rem;
height: 10rem;
}
.item:last-child .content {
background: red;
}
<h3>Shrink the viewport to get an idea of what's the intended scenario</h3>
<ul class="current">
<li><div></div></li>
<li><div></div></li>
</ul>
<h3>Visual representation of the overlap behavior</h3>
<section>
<div class="item"><div class="content"></div></div>
<div class="item"><div class="content"></div></div>
</section>
基本上,我想要的是让图像在灵活的上下文中相互“重叠”,意思是一种适用于 N 种情况的解决方案。
【问题讨论】:
-
将容器设置为 flex-wrap。然后使用像 40% 宽度和 60% 宽度这样的百分比。比上要弹出的图像。以像素为单位设置最小宽度。当它到达那个点时,它会弹出。
-
我的目标是让它不换行,而是让第一个元素缩小。根据示例,
overflow: hidden确实实现了我正在寻找的东西;但是我想知道是否还有其他技巧会触发缩小,同时仍然渲染溢出的内容。