【发布时间】:2017-11-25 20:56:09
【问题描述】:
我想创建一个简单的弹出框显示在适当的位置(想想按钮下方的组合框列表)。弹出框应显示在现有元素上,即不预先分配空间。
有很多使用 `position: relative -> overflow: hidden -> position: absolute' 层次结构和工作直到弹出框从容器底部流出的例子,在这种情况下,它的大小会影响父容器并创建一个滚动。
这是codepen sample。我想要得到的是在最右边的列上没有滚动。
<div class="main">
<div class="column">
<h2>no overflow</h2>
<div class="tall">x</div>
<div class="tall">x</div>
</div>
<div class="column">
<h2>basic overflow</h2>
<div class="tall">x</div>
<div class="tall">x</div>
<div class="tall">x</div>
</div>
<div class="column">
<h2>popover without overflow</h2>
<div class="tall">x</div>
<div class="overlay">
popover should be vislble below
<div class="overflow">
<div class="absolute short">
z
</div>
</div>
</div>
<div class="tall">x</div>
</div>
<div class="column">
<h2>popover with overflow</h2>
<div class="tall">x</div>
<div class="overlay">
popover should be vislble below
<div class="overflow">
<div class="absolute">
z
</div>
</div>
</div>
<div class="tall">x</div>
</div>
</div>
还有 scss 文件:
html, body {
height: 95%;
}
.main {
display: flex;
flex-direction: row;
border: 2px solid red;
height: 100%;
.column {
margin-left: 20px;
height: 100%;
flex: 1;
border: 1px solid black;
overflow-y: auto;
.tall {
height: 300px;
border: 1px solid blue;
}
.overlay {
position: relative;
.overflow {
background: #F00;
overflow: hidden;
.absolute {
opacity: 0.5;
width: 100%;
height: 600px;
position: absolute;
background: #FF0;
&.short {
height: 200px;
}
}
}
}
}
}
【问题讨论】:
-
您是否尝试过这样做?如果是这样,请分享您的代码。
-
如果弹出框比容器大,为什么不创建滚动条呢?否则,它的某些部分将被隐藏。
-
使用位置:绝对值和负值不会影响父容器
-
对不起,由于某种原因,我在完成代码之前发布了。附上代码和链接
-
我不想滚动的原因是我希望以后能够查询弹出框并查看它是否在屏幕外并进行 js 操作
标签: html css layout flexbox overflow