固定标题可滚动表与引导程序

时间:2015-04-25 08:55:40

标签: css twitter-bootstrap fixed-header-tables

如何通过css将每个单元格高度设置为一行中单元格的最大高度。 我想将每个单元格的高度设置为该行中单元格的最大高度 使用现有代码。我不想让任何div内部实现这一点,只有css

HTML

<div class="panel panel-default">
        <div class="panel-body">
            <table id="myTable" class="table table-fixedheader table-bordered table-striped">
                <thead>
                    <tr>
                        <th width="15%">Column1Column1Column1Column1</th>
                        <th width="15%">Column2</th>
                        <th width="15%">Column3</th>
                        <th width="15%">Column4</th>
                        <th width="40%">Column5</th>
                    </tr>
                </thead>
                <tbody style="height:110px">
                    <tr>
                        <td width="15%">aaaaaaaaaaa</td>
                        <td width="15%">bbbbbbbbbbb</td>
                        <td width="15%">ccccccccccc</td>
                        <td width="15%">dddddddddddddddddddddddddddddddddddddddddd</td>
                        <td width="40%">eeeeeeeeeee</td>
                    </tr>
                    <tr>
                        <td width="15%">aaaaaaaaaaa</td>
                        <td width="15%">bbbbbbbbbbb</td>
                        <td width="15%">ccccccccccc</td>
                        <td width="15%">ddddddddddd</td>
                        <td width="40%">eeeeeeeeeee</td>
                    </tr>
                    <tr>
                        <td width="15%">aaaaaaaaaaa</td>
                        <td width="15%">bbbbbbbbbbb</td>
                        <td width="15%">ccccccccccc</td>
                        <td width="15%">ddddddddddd</td>
                        <td width="40%">eeeeeeeeeee</td>
                    </tr>
                    <tr>
                        <td width="15%">aaaaaaaaaaa</td>
                        <td width="15%">bbbbbbbbbbb</td>
                        <td width="15%">ccccccccccc</td>
                        <td width="15%">ddddddddddd</td>
                        <td width="40%">eeeeeeeeeee</td>
                    </tr>
                    <tr>
                        <td width="15%">aaaaaaaaaaa</td>
                        <td width="15%">bbbbbbbbbbb</td>
                        <td width="15%">ccccccccccc</td>
                        <td width="15%">ddddddddddd</td>
                        <td width="40%">eeeeeeeeeee</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

CSS

/*
Force table width to 100%
*/
 table.table-fixedheader {
    width: 100%;   
}
/*
Set table elements to block mode.  (Normally they are inline).
This allows a responsive table, such as one where columns can be stacked
if the display is narrow.
*/
 table.table-fixedheader, table.table-fixedheader>thead, table.table-fixedheader>tbody, table.table-fixedheader>thead>tr, table.table-fixedheader>tbody>tr, table.table-fixedheader>thead>tr>th, table.table-fixedheader>tbody>td {
    display: block;
}
table.table-fixedheader>thead>tr:after, table.table-fixedheader>tbody>tr:after {
    content:' ';
    display: block;
    visibility: hidden;
    clear: both;
}
/*
When scrolling the table, actually it is only the tbody portion of the
table that scrolls (not the entire table: we want the thead to remain
fixed).  We must specify an explicit height for the tbody.  We include
100px as a default, but it can be overridden elsewhere.

Also, we force the scrollbar to always be displayed so that the usable
width for the table contents doesn't change (such as becoming narrower
when a scrollbar is visible and wider when it is not).
*/
 table.table-fixedheader>tbody {
    overflow-y: scroll;
    height: 100px;

}
/*
We really don't want to scroll the thead contents, but we want to force
a scrollbar to be displayed anyway so that the usable width of the thead
will exactly match the tbody.
*/
 table.table-fixedheader>thead {
    overflow-y: scroll;    
}
/*
For browsers that support it (webkit), we set the background color of
the unneeded scrollbar in the thead to make it invisible.  (Setting
visiblity: hidden defeats the purpose, as this alters the usable width
of the thead.)
*/
 table.table-fixedheader>thead::-webkit-scrollbar {
    background-color: inherit;
}


table.table-fixedheader>thead>tr>th:after, table.table-fixedheader>tbody>tr>td:after {
    content:' ';
    display: table-cell;
    visibility: hidden;
    clear: both;
}

/*
We want to set <th> and <td> elements to float left.
We also must explicitly set the width for each column (both for the <th>
and the <td>).  We set to 20% here a default placeholder, but it can be
overridden elsewhere.
*/

 table.table-fixedheader>thead tr th, table.table-fixedheader>tbody tr td {
    float: left;    
    word-wrap:break-word;     
}

Check out my fiddle

0 个答案:

没有答案