在我的页面中,我有一个基于其父元素的高度为 100% 的元素;但是,我希望此元素在必要时自动垂直滚动。这是 my example .
我做不到。
我添加了以下 CSS:
height:100%;
max-height:100%;
事实上,我想要的是确保.content
总是在.container
里面.像这样:
(顺便说一句,在上图中,我使用了 max-height:400px
,应该避免使用它,因为它的最大高度应该基于 .container
的高度)
有什么想法吗?
最佳答案
这接近您正在寻找的解决方案,但您可能需要调整填充等以获得更美观的外观:http://jsfiddle.net/GJ5yM/
新的 CSS:
.content{
height:100%;
position: absolute;
}
.windowcontent{
background-color: white;
padding: 10px;
max-height:100%;
position:relative;
overflow-y:auto;
}
关于css - 设置溢出 :auto with height 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14228944/