简体   繁体   English

如何在底部垂直对齐div并自动溢出

[英]How to vertically align a div at the bottom and overflow auto

I have the following html 我有以下HTML

<div class="ex">
<div class="ex0">
<div class="ex1">
 <div class="ex2">
 ....
 </div>
 <div class="ex3">
 ....
 </div>
</div>
</div>
</div>

ex0 is absolutely positioned. ex0绝对定位。 ex1, ex2, ex3 are relatively positioned. ex1,ex2,ex3相对定位。 ex0 and ex1 has overflow auto. ex0和ex1具有自动溢出功能。 ex1 has a min height of 480px; ex1的最小高度为480px; and ex2 has a height of 100%; ex2的高度为100%;

Two questions 两个问题

  • How do we make sure that ex3 is always aligned at the bottom of the div ex1? 我们如何确保ex3始终在div ex1的底部对齐? (I currently use min height on ex2, but I don't want to do that. I tried using flexbox, but the boxes get distorted when I do that. I tried absolute position, but when you make the screen smaller in height, the div overlaps the others. (我目前在ex2上使用min height,但是我不想这样做。我尝试使用flexbox,但是这样做时盒子会变形。我尝试使用绝对位置,但是当您使屏幕的高度变小时, div与其他重叠。
  • When I make the window smaller in height, the scrolling no longer works. 当我将窗口的高度减小时,滚动不再起作用。 I cannot scroll down the div. 我无法向下滚动div。 Does anyone know why? 有人知道为什么吗? It gets stuck 1/4 down the div. 它在div处陷下1/4。

Here's the CSS: 这是CSS:

.ex {
   position: absolute;
   min-width: 1000px;
   min-height: 480px;
   left: 0px;
   right: 0px;
   top: 0px;
   bottom: 0px;
   z-index: 200;
   background: #262626;
}

.ex0 {
    box-sizing: border-box;
    position: absolute;
    display: block;
    width: 430px;
    right: 0px;
    top: 0px;
    bottom: 0px;
    padding: 0px;
    margin: 0px;
    border-left: 2.5px solid #1c1c1c;
    overflow: auto;
}

.ex1 {
  position: relative;
  height: 100%;
  padding: 52.5px 65px 40px 50px;
  overflow: auto;
}

.ex2 {
    min-height: calc(100% - 250px);
}

.ex3 {
   position: relative;
   width: 100%;
} 

Do change your "ex3" class by below changes for your first question's answer. 请针对以下第一个问题的答案,通过以下更改来更改“ ex3”类。 It will place ex3 div at the bottom of page. 它将ex3 div放在页面底部。

.ex3 {
    position: absolute;
    bottom: 0;
} 

About your second question. 关于第二个问题。 Scroll bar is displaying on browser screen when I created demo using html and css you provided in question. 当我使用您提供的html和css创建演示时,滚动条显示在浏览器屏幕上。 And when I resize screen for smaller height, scroll bar is persist on page. 当我将屏幕尺寸调整为较小的高度时,滚动条仍保留在页面上。

Please check jsfiddle link to get more idea about it. 请检查jsfiddle链接以了解更多信息。

Delete .ex2 and write in .ex3: 删除.ex2并写入.ex3:

.ex3 {position: absolute; width: 100%; bottom: 0;}

the scroll bar should be work! 滚动条应该正常工作!

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

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