CSS垂直表布局

问题描述:

我有这样做的div表:CSS垂直表布局

<div class="table"> 
    <div class="tRow A"> 
     <div class="tCell"> 
      Test 
     </div> 
    </div> 
    <div class="tRow B"> 
     <div class="tCell"> 
      <!-- content here --> 
     </div> 
    </div> 
    <div class="tRow C"> 
     <div class="tCell"> 
      Test 
     </div> 
    </div> 
</div> 

与下面的CSS:

body, html{ 
    height: 100%; 
} 

.table{ 
    display: table; 
    height: 100%; 
    max-height: 100%; 
    width: 200px; 
    table-layout: fixed; 
} 

.tRow{ 
    display: table-row; 
} 

.tCell{ 
    display: table-cell; 
} 

.B { 
    background: yellow; 
} 

.B .tCell{ 
    overflow: hidden; 
} 

.C{ 
    height: 50px; 
    background: green; 
} 

http://jsfiddle.net/HtA43/

现在我需要(我不是能够得到这个工作)是,该表格呈现100%的高度。 rowA高达其内容rowC底部固定高度。并且rowB应该填充剩下的空间。

目前为止,但当rowB的内容超过其大小时,单元格和表格随之增长。我需要的是rowB不会增长,但溢出隐藏。

有什么建议吗?

+0

你有什么问题? – falguni

+0

这里的问题是为什么你使用表格布局来做到这一点? – DaniP

+0

因为我认为这将是实现这一目标的唯一方法。 (一行autoSized,一个固定,一个填充行在中间)如果你有建议不具有表格布局,这将是伟大的。 – Chris

根据您的要求,您有overflow:hidden,这使得布局更容易实现。你可以有一个这样的结构:

<div class="container"> 
<div class="A"> 
     Test 
</div> 
<div class="B"> 
    Test.... 
</div> 
<div class="C"> 
     Test 
</div> 
</div> 

然后短短风格:

.container{ 
    height: 100%; 
    width: 200px; 
    position:relative; 
    overflow:hidden; 
} 
.B { 
    min-height:100%; 
} 
.C{ 
    position:absolute; 
    bottom:0; 
    width:100%; 
    height: 50px; 
} 

入住这Demo Fiddle

+0

绝对看起来更像是比刚性表格布局更为类似的方式 – Tyblitz

+0

我认为这几乎是我需要的,但这种方法的问题(为什么我通常更喜欢div-table风格的原因之一)是中间的100%div落后于底部固定的一个。 (你确实可以设置一个大小为'C'的填充符'B',但是我需要应用到'B'的一些jquery插件无法应付这种情况)。 – Chris

+0

实际上'B'获得了100%高度ob的容器,它是'容器',它使得'B'总是超过容器并到达页面外部,这使得它不可能滚动。 – Chris