html表格整体高度怎么设置,如何设置html表格的高度和列宽?

I am attempting to control the height of a table body so that a scrollbar appears when more data than fits in a view is displayed, thead must stay visible. At the same time I'm trying to control the width of the table columns.

The table height can be controlled by setting 'display: block' in the table body css. The table body will now be limited by the container height or any height the table body is set to. This messes up the column widths though.

The column widths can be assured by setting as desired. As long as the tbody isn't set to 'display: block' the columns display properly but the tbody is out of control and ignores any height you may have set.

I'm trying to do this to make it possible for the result to be easily chapter 508 compliant for screen reader technology for those with disabilities. AT this point, I'm planning to convert to jquery.dataTables which puts a view port over top of a table so I can keep the 508 compliance and get the functionality I need. This seems way over the top for what I'm wanting to accomplish but I can't find a simple way to do it with a native table and basic css.

Test code is as follows:

MonthSavings

January$100February is a long month that seems like it could go on forever!$80March$180April$86May$98June$29July$44August$244

#div1 {

height: 100px;

width: 400px;

padding: .5px;

border: 1px solid red;

}

colgroup {

width: 100%;

}

#col-1 {

width:70%;

}

#col-2 {

width:30%;

}

table {

width: 100%;

table-layout: auto;

}

thead {

background-color: #B2DFFF;

}

tbody {

height: 72px;

overflow-y: scroll;

background-color: #F0F0F0;

/* display:block; This will set column width correctly but it messes up tbody height */

display:block; /* This will allow height to be set but it messes up columns width */

}

Does anyone have any ideas?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值