简体   繁体   English

获取表格以填充剩余宽度

[英]Get table to fill remaining width

I'm having a bit of trouble getting my table to fill the remaining space within a floated element. 我在使表格填充浮动元素中的剩余空间时遇到麻烦。 This is what I'm trying to achieve: 这是我要实现的目标:

示例表

And this is what I have so far: 这就是我到目前为止所拥有的:

HTML: HTML:

<div class="parent">
    <div class="left">

    </div>
    <div class="right">
        <table>
            <tr>
                <td>1</td>
                <td>2</td>
            </tr>
        </table>
    </div>
</div>

CSS: CSS:

.parent {
    height: auto;
    overflow: hidden;
}
.left {
    width: 125px;
    background: blue;
    float: left;
    height: 100px;
}
.right {
    background: red;
    height: 100px;
}
table {
    background: green;
    /*width: 100%;*/
}

I tried width: 100% but that doesn't take into account the left-floated element and the table gets hidden outside the container. 我尝试了width: 100%但这没有考虑到左浮动元素,并且表格被隐藏在容器外部。 I also tried display: block but that causes the <td> to no longer function as they would if they were inside a table. 我还尝试了display: block但这会导致<td>不再像在表中那样起作用。

jsFiddle 的jsfiddle

As you are float ing your .left div with the fixed width you can use a combination of the overflow:auto and width:auto (default value) to expand your .right div. 当您以固定width float .left div时,可以结合使用overflow:autowidth:auto (默认值)来扩展.right div。 Also uncomment width:100% to make table take the full width of the .right div: 还取消注释width:100% ,使表格采用.right div的整个宽度:

.right {
  overflow:auto;
}

table {
  width: 100%;
}

Example

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

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