【问题标题】:Make a left float expand to match two rightfloated siblings使左浮动扩展以匹配两个右浮动兄弟
【发布时间】:2014-04-03 16:09:53
【问题描述】:

我有一个装有 3 个盒子的容器。两个盒子向右浮动,占据了父 div 高度的 50% 左右(overflow-y: 隐藏在父 div 上),所以它们的大小相同。他们有一个浮动到左边的兄弟姐妹,我想根据它的 2 个兄弟姐妹的高度(因此是父高度)扩展高度。

如果可以避免的话,我不想将父级设置为固定高度(因为如果浏览器大小发生变化,它可以改变大小)。

一个JsFiddle

  <article>
    <div class="box-container">
        <section class="box-half left-box">
            <h3>Bigger box</h3>

            <div class="chart">
                <p>I want this box to fill the entire height</p>
            </div>
        </section>

        <section class="box-half">
            <div>
                <h3>One half box</h3><span>With some text</span>
            </div>
        </section>

        <section class="box-half">
            <div>
                <h3>Another half box</h3><span>With another text</span>
            </div>
        </section>
    </div>
</article>




 *, *:before, *:after {
    box-sizing: border-box;
}

.left-box {
    background: white !important; 
}

.box-container {
    overflow-y: hidden;
}

article {
    width: 100%;
    background: green;
}

.box-full,
.box-half {
    width: 100%;
    float: left;
    padding: 0.25em;
    text-align: center;
}

.box-half {
    width: 50%;
    background: blue;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    您可以尝试使用display:tabledisplay:table-cell 而不是float...见this Fiddle

    【讨论】:

    • 如果我希望 .chart 能够扩展表格单元格(#left)的整个高度,除了导致

      biggerbox

    • 什么意思?你想让它垂直居中吗?
    • 这个小提琴显示了它:jsfiddle.net/8vq5c/5 里面的桌子也应该扩大高度。没有将 .chart 设置为固定高度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 2012-09-03
    相关资源
    最近更新 更多