2个div完美实现GridView表头固定
华得 2008-07-15 02:20:49 <style type="text/css">
.fixedheader
{
background-color: #ffffff;
color: #ffffff;
padding: 2px 2px 2px 2px;
text-align: center;
position: relative;
table-layout: fixed;
top: expression(this.offsetParent.scrollTop);
z-index: 10;
}
.fixedheader th
{
text-overflow:ellipsis;
overflow:hidden;
white-space:nowrap;
background-color: #4682B4;
}
</style>
<div style="overflow-y:auto;" >
<div style="margin-top:-1px">
<asp:GridView runat="server">
<Columns>
<asp:BoundField HeaderText="序 号">
</asp:BoundField>
<asp:BoundField HeaderText="学号">
</asp:BoundField>
<asp:BoundField HeaderText="姓名">
</asp:BoundField>
<asp:BoundField HeaderText="ID">
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="fixedheader" Wrap="False" />
<RowStyle CssClass="FirstLine" />
<AlternatingRowStyle CssClass="SecondLine"/>
</asp:GridView>
</div>
</div>
关键是margin-top:-1px,没有此句会出现空隙。
这个问题花了兄弟一周时间才解决。