简体   繁体   English

表全宽div

[英]table full width div

I'm trying to solve a problem where a page is meant to have a fixed-width left-hand nav, and a main div to its right, taking up the rest of the width of the screen. 我正在尝试解决一个问题,即页面意味着有一个固定宽度的左手导航,而右边的主要div占据了屏幕宽度的其余部分。

The main div on the right is meant to contain a table, and I want the table to expand to fit the width of the entire width of the main area. 右边的主要div用于包含一个表格,我希望表格能够扩展到适合主要区域整个宽度的宽度。

Is there a way to do this in CSS? 有没有办法在CSS中这样做?

I have code similar to this: 我有类似这样的代码:

<div id="overallDiv">

<div id="lhn">
Left-hand nav
</div>
<div id="mainBody">
    <table>
        <tr><td>A1</td><td>A2</td><td>A3</td></tr>
        <tr><td>B1</td><td>B2</td><td>B3</td></tr>
        <tr><td>C1</td><td>C2</td><td>C3</td></tr>
        <tr><td>D1</td><td>D2</td><td>D3</td></tr>
    </table>
</div>

</div>

My CSS is similar to this: 我的CSS类似于:

#lhn
{
    display:inline;
    float:left;
    width: 100px;
}
#mainBody
{
    display:inline;
    float:left;
}

How can I make the table fill the remaining part of the page? 如何让表格填满页面的其余部分?

I would use the following: 我会使用以下内容:

#overallDiv {width: 100%;}
#lhn {width: 100px; float: left;}
#mainBody{float: left;}
#mainBody table {width: 100%;}

This sets your wrapper to 100% of the available screen, makes your left-hand nav 100px, and #mainBody 100% of what is left. 这会将您的包装器设置为可用屏幕的100%,使您的左侧导航100px,以及#mainBody剩余100%。

The easiest and least "hackish" way of doing this at this at this time is to deploy display: table and display: table-cell : 此时执行此操作的最简单且最简单的“hackish”方式是部署display: tabledisplay: table-cell

​#overallDiv {
    display: table;
    width: 100%;
}
#lhn,
#mainBody {
    display: table-cell;
}
#lhn {
    width: 200px;
    background: #ddd;
}
​#mainBody > table {
    width: 100%;
}​

http://jsfiddle.net/wxnBQ/ http://jsfiddle.net/wxnBQ/

Using float for non-text layout is a long-in-the-tooth "borrowing" of it's effect; 使用float进行非文本布局是一种长期的“借用”它的效果; the sooner is crawls into the grave of "useful ideas back in those days", the better we'll all be. 越早进入“那些日子里有用的想法”的坟墓,我们就越好。

The "best" approach for this would, of course, be to do a Flexbox implementation ( W3C proposed specification ). 当然,“最佳”方法是进行Flexbox实现( W3C提出的规范 )。 That day's not here yet. 那天还不到。

设置display:table为#overall,display:table-cell为内部div

#overallDiv {width: auto; float: left;}
#lhn {width: 100px; float: left;}
#mainBody{float: left; width: auto;}
#mainBody table {width: 100%;}

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

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