简体   繁体   English

固定容器div时,嵌套子div无法滚动

[英]Nested child div not scrollable when container div is fixed

I have a container div (modal) that is set to position: fixed (absolute is not an option for my purpose). 我有一个容器div(模态),它的position: fixed设置为position: fixed (绝对不是我的选择)。 Inside of this container I have two columns. 在此容器中,我有两列。 One of these columns contains tab buttons with below them some content or a form. 这些列之一包含选项卡按钮,并在其下方包含一些内容或表格。 This content (only the content, not the tabs) should be scrollable but I can't figure out how. 此内容(仅内容,而不是选项卡)应该是可滚动的,但我不知道如何。

The height of the tabs can change so the solution can't contain a fixed height for the tab bar. 选项卡的高度可以更改,因此解决方案不能包含选项卡栏的固定高度。

I've tried to make the whole column scrollable first by setting the column to position: relative , min-height: 100% and overflow-y: scroll but this first try didn't even work. 我试图通过将列设置为position: relativemin-height: 100%overflow-y: scroll来使整个列首先可overflow-y: scroll但是第一次尝试什至不起作用。

Codepen with basic setup Codepen基本设置

EDIT 编辑

Not a duplicate of How to make child div scrollable when it exceeds parent height? 不是重复子级div超过父级时如何使子级div滚动?

  • I'm working inside a fixed container 我正在固定容器内工作
  • I'm working with flexible heights 我正在使用灵活的高度
  • Trying to achieve a css only solution 尝试实现仅CSS的解决方案

This issue is occurring because you are not declaring "max-height" to container ".details-column". 发生此问题的原因是您没有在容器“ .details-column”中声明“最大高度”。

Try below CSS : 尝试下面的CSS:

.content{ max-height: 400px; .content {max-height:400px; overflow-y: auto; 溢出-y:自动; } }

Note: You have to set fixed height or fixed max-height of the container otherwise container won't know when it has to scroll data. 注意:您必须设置容器的固定高度或固定的最大高度,否则容器将不知道何时需要滚动数据。

Excerpt from W3School : W3School的节选

The overflow property only works for block elements with a specified height. 溢出属性仅适用于具有指定高度的块元素。

but since you've flexible height element doesn't know when to overflow as it will just keep on growing. 但由于高度灵活,高度元素不知道何时会溢出,因为它将不断增长。

you'll most likely have to define a height or max-height or even use JS to calculate height, other suggestion i can make is to play around with white-space property as well as calc() for height. 您很可能必须定义一个高度或最大高度,甚至使用JS来计算高度,我可以提出的其他建议是使用white-space属性以及calc()作为高度。

Edit: Here is a very good source to help you understand overflows: https://www.brunildo.org/test/Overflowxy2.html 编辑: 这是一个很好的资源来帮助您了解溢出: https : //www.brunildo.org/test/Overflowxy2.html

Good Luck. 祝好运。

By applying following css your div will be scrollable. 通过应用以下CSS,您的div将可滚动。

.content{
  height: 80%;
  overflow-y: auto; 
}

this is because there is not much content to make it scroll.. put some content and try.. check below link 这是因为没有太多内容可以滚动。.放一些内容然后尝试..检查下面的链接

overflow-y: auto 

add this to the modal class. 将此添加到模式类。 thanks 谢谢

https://codepen.io/Xenio/pen/mvbpJV 99 https://codepen.io/Xenio/pen/mvbpJV 99

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

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