HTML中的table加滚动条+修改样式

HTML中的table加滚动条

<table class="table">
  <thead>
    <tr>
      <td>我是表头1</td>
      <td>我是表头2</td>
      <td>我是表头3</td>
      <td>我是表头4</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
    <tr>
      <td>内容1</td>
      <td>内容2</td>
      <td>内容3</td>
      <td>内容4</td>
    </tr>
  </tbody>
</table>  
.table{
  width: 500px;
  border-collapse:collapse;
  background-color: rgba(45,172,255,.1);
  border-right: 1px solid rgba(0,175,237,.3);
  border-top: 1px solid rgba(0,175,237,.3);
}
.table tr td{
  border-bottom: 1px solid rgba(0,175,237,.3);
  border-left: 1px solid rgba(0,175,237,.3);
  color: #fff;
  font-size: 16px;
  padding: 5px 10px;
  text-align: center;
}
.table tr td:nth-child(1),
.table tr td:nth-child(2),
.table tr td:nth-child(3){
  width: 100px;
}
.table>tbody>tr,.table>thead{
  display: table;
  width: 100%;
  table-layout: fixed; /* 重要  表格固定算法 */
}
.table>tbody{
  height: 200px;
  overflow: hidden;
  display: block;
  overflow: hidden;
  overflow-y: auto;
}
  /* 定义滚动条样式 */
::-webkit-scrollbar {
  width: 24px;
  height: 143px;
  background-color: #ffffff;
}
 
/*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-track {
  box-shadow: inset 0 0 0px rgba(240, 240, 240, .5);
  border-radius: 10px;
  background-color: rgba(240, 240, 240, .5);
}
 
/*定义滑块 内阴影+圆角*/
::-webkit-scrollbar-thumb {
width: 24px;
  height: 143px;
  background-color: #2D8EFF;
  border-radius: 10px;
  /* box-shadow: inset 0 0 0px rgba(240, 240, 240, .5);
  background-color: rgba(240, 240, 240, .5); */
}

分别来自tbody设置超出固定的高度出现滚动条,没超出不显示。 - 小伍w - 博客园 (cnblogs.com)以及css 设置overflow:scroll 滚动条的样式 - 遇你温柔如初 - 博客园 (cnblogs.com)

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值