添加表滚动条

时间:2015-05-21 08:49:09

标签: html css razor

在HTML 5中,使用谷歌浏览器浏览器尝试为表格的详细信息部分添加滚动条。

css:

    /*Table section for scollbar*/
table.tableSection {    
    display: table;
    width: 100%;
    max-height: 30px;
}
table.tableSection thead, table.tableSection tbody {
    float: left;
    width: 100%;
}

/*table.tableSection tbody {
    overflow: auto;
    max-height: 30px;
}*/

table.tableSection tr {
    width: 100%;
    display: table;
    text-align: left;
}
table.tableSection th, table.tableSection td {
    width: 33%;
    border: 1px solid black;
}

thead{
    overflow-y: scroll;
    position: relative;
}

tbody{
    overflow: auto;
    max-height: 10px;
}

剃刀代码:

<table class="table">
                <thead>
                    <tr>
                        <th>
                            @Html.DisplayNameFor(model => model.GenderID)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Gender)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.GenderShort)
                        </th>
                    </tr>
                </thead>

                <tbody>
                    @foreach (var item in Model)
                    {   
                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.GenderID, new { @class = "txtGenderID", id = "txtGenderID" })
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Gender, new { @class = "txtGender", id = "txtGender" })
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.GenderShort, new { @class = "txtGenderShort", id = "txtGenderShort" })
                            </td>

                            <td>
                                @Html.ActionLink("Edit", "_GenderEdit", new { id = item.GenderID }, new { @class = "EditActionLink" })   |
                                @Html.ActionLink("Delete", "_GenderDelete", new { id = item.GenderID }, new { @class = "DeleteActionLink" })
                            </td>
                        </tr>
                    }
                </tbody>         

            </table>

在代码呈现时显示的样式:

tbody {
  overflow: auto;
  max-height: 30px !important;
}

但是桌子的渲染幅度要大得多,没有滚动条

1 个答案:

答案 0 :(得分:0)

你可以试试这个

thead, tbody { display: block; }

tbody {
  height: 100px;      
  overflow-y: auto;   
}
相关问题