html - 如何使所有三个表显示在同一高度

标签 html css

我有三个表 table1,table2,table3 都包裹在一个表中,同时向表中添加不同大小的内容,每个表扩展到不同的高度,即使添加不同大小的内容,如何使所有三个表显示在相同的高度内容

HTML:

<div class="csdiv">
<table cellpadding="2" cellspacing="0">
    <tr valign="top">
        <td>
            <table class="cstable" width="100%" height="265">
                    <tr height="35">
                        <th width="33%" nowrap>Table1</th>
                    </tr>
                    <tr>
                        <td valign="top" bgcolor="FFFFFF" width="275">


                        </td>
                    </tr>
            </table>
        </td>
        <td>
            <table class="cstable" width="100%" height="265">
                    <tr height="35">
                        <th nowrap width="34%" nowrap>Table2</th>
                    </tr>
                    <tr>
                        <td valign="top" bgcolor="FFFFFF" width="275">

                        </td>
                    </tr>
            </table>
        </td>
        <td>
            <table class="cstable" width="100%" height="265">
                    <tr height="35">
                        <th nowrap width="33%" nowrap>Table3</th>
                    </tr>
                    <tr>
                        <td valign="top" bgcolor="FFFFFF" width="275">


                        </td>
                    </tr>
            </table>
        </td>                                  
    </tr>
</table>
</div>

CSS:

.csdiv {
    font-family: 'Trebuchet MS',Tahoma,Arial,sans-serif;
    font-size: 12px;
    line-height: 1em;
}
.cstable {
    border-collapse: collapse;
    border-color: #666666;
    border-style: solid;
    border-width: 1px;
    font-family: 'Trebuchet MS',Tahoma,Arial,sans-serif;
    font-size: 12px;
    line-height: 1em;
}
.cstable th {
    background-color: #A3C2FF;
    border-collapse: collapse;
    border-color: #666666;
    border-style: solid;
    border-width: 1px;
    color: #000000;
    font-family: 'Trebuchet MS',Tahoma,Arial,sans-serif;
    font-size: 12px;
    font-weight: bold;
    line-height: 1em;
    text-align: left;
}

JSFIDDLE:DEMO

最佳答案

你的父元素没有设置height,所以table的高度只等于内容。要让它全高,添加

 html,body{
    height:100%; /*give full height to document */
    width:100%;
    margin:0;
    padding:0;
 }
 table{
    height:100%; /* stretch table to parents height*/
 }

demo

关于html - 如何使所有三个表显示在同一高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21042195/

相关文章:

javascript - 具有粘性/固定标题的水平和垂直响应表?

javascript - 发送表单时向表单插入新元素会导致问题(空数据)

javascript - 让脚本在没有 .text 的情况下工作

javascript - 如何使用 Javascript 将开关设置为关闭?

html - 使用带有 IMG 标签的 Sprite ?

javascript - 当我们点击为复选框分配的标签时,Chrome 和 IE 不会按时触发更改事件

css - 类属性不适用于按钮

html - 如何将网页宽度(以像素为单位)缩放到任何屏幕尺寸?

html - 如何让section和aside接触页脚?

css - 当给定集合为 nil 时渲染部分集合