Dialog with max height and dynamic Content that scrolls + footer css

我的未来我决定 提交于 2019-12-10 23:51:37

问题


I have a dialog with position: absolute and a max-height set. The max-height property is set from outside by a javscript framework (jQuery UI Dialog), so I don't have any control over it. Inside I have 2 divs: one that is filled with dynamic content and a static footer. I want the dialog to grow with it's content until max-height is reached and after that my content div should display a scrollbar.

The html looks like this:

<div class="dialog">
    <div class="content">
        This text doesn't mean much it's just supposed to fill content.<br>
        This text doesn't mean much it's just supposed to fill content.
        ...
    </div>
    <div class="copyright">
        © copyright 2015 by some chilled dude
    </div>
</div>

And the css like this:

.dialog {
    position: absolute;
    left: 100px;
    top: 100px;
    max-height: 300px;
    border: solid black 1px;
}

.content {
    height: auto;
    overflow: auto;
    max-height: calc(100% - 20px);
}

The problem is, the content will always blowout its surrounding dialog and push down the footer.

example

If I set the the height of the dialog div everything is fine.

example2

I can calculate the height with javascript and set it on my dialog (example3), but I would like to do this using only css. Is that possible ?


回答1:


As an alternative approach, you could use flexbox.

.dialog {
    position: absolute;
    left: 100px;
    top: 100px;
    max-height: 300px;
    border: solid black 1px;
    display: flex;
    flex-flow: column;
}
.content {
    overflow: auto;
}

jsfiddle



来源:https://stackoverflow.com/questions/32993779/dialog-with-max-height-and-dynamic-content-that-scrolls-footer-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!