html - 如何制作溢出 :auto expand to the height of its contents up to a point? 的外部 div

标签 html css

我有一个 div (frame_outer),其中包含另一个 div (frame_inner),其中包含动态内容。我想要的是 frame_outer 自动扩展它的高度,直到它达到 frame_inner 的高度或它自己的最大高度。

可能值得一提的是,我首先使用 frame_outer 的原因是因为有时我希望 frame_inner 的内容水平扩展而不溢出页面的一侧(因此 overflow:auto on frame_outer ).

JSFiddle is here.

我试过以各种方式使用 clear:bothheight:autodisplay:block,但似乎没有任何效果。

Fiddle 的代码:

HTML:

<div class="frame_outer">
    <div class="frame_inner">
        <ul class="my-col">Important stuff</ul>
        <ul class="my-col">Important stuff
            <li class="inside-col">Cool stuff</li>
            <li class="inside-col">Cool stuff</li>
            <li class="inside-col">Cool stuff yay yay cool stuff</li>
            <li class="inside-col">Cool stuff</li>
            <li class="inside-col">Cool stuff</li>
            <li class="inside-col">Cool stuff</li>
            <li class="inside-col">Cool stuff</li>
        </ul>
        <ul class="my-col">Important stuff</ul>
    </div>
</div>

CSS:

.frame_outer {
    overflow: auto;
    position: relative;
    border: 1px solid black;
    max-width: 320px;
    max-height: 640px;
    /* I don't know how to make my stuff appear without manually setting height like below */
    /* height: 1000px; */
    /* What I want is for frame_outer to expand automatically either until it hits the height of frame_inner or its max-height*/
}
.frame_inner {
    overflow: hidden;
    position: absolute;
    top: 0;
    left: 0;
    width: 150%;
}
.my-col {
    list-style-type: none;
    float: left;
    margin: 0;
    border: 1px solid white;
    background: #eeeeee;
    width: 20%;
}
.inside-col {
    background: #ebe7eb;
    padding: 4px;
    margin-top: 100px;
    border: solid #808080 1px;
    width: 90%;
    word-wrap: break-word;
    display: inline-block;
}

最佳答案

问题的发生是因为 frame_inner 对其有绝对定位。

删除它并仅提供 width 和 float 属性使其出现在 frame_outer 中。而且它是水平和垂直滚动的。

这是我更新的类,

.frame_inner {
    float:left;
    width: 150%;
}

检查更新的 JSFIDDLE

希望这能解决您的问题。

关于html - 如何制作溢出 :auto expand to the height of its contents up to a point? 的外部 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30739042/

相关文章:

jquery - 如何通过从另一个弹出窗口传递的 id 制作弹出窗口显示列表?

php - 阻止或清除 HTML/CSS 标签

javascript - 如何创建可折叠的网格、表格或列

javascript - 如何在显示时隐藏元素: none doesn't work

javascript - 3个自适应高度的div(基于最高的)不刷新

javascript - 如何引用 CSS 或 JS 文件中的元素以实现最快的解析?

php - 普通网站的 Wordpress 主题

javascript - 如何让按钮停在第一张和最后一张图片

html - Css-背景图像在顶部和底部被裁剪

javascript - Skrollr 淡入淡出文本不起作用,但所有其他 skrollr 元素都起作用