vue里面原生的table表格纯css固定头部与左侧第一列

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>CSS实现表头与列固定</title>
    <!--引用vue.js -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
       .main{
           width:1000px;
           overflow:auto;
           height:625px;
       }
       td,th{
          border:1px solid gray;
          width:100px;
          height:30px;
       }
       th{
        background-color:lightblue;
       }
       table{
         table-layout:fixed;
         width:2000px;
       }
       td:first-child,th:first-child{
          position:sticky;
          left:0;
          z-index:1;
          background-color:lightpink;
       }
       thead tr th{
           position:sticky;
           top:0;
       }
       th:first-child{
          z-index:2;
          background-color:lightblue;
       }
    </style>
</head>
<body>
<!--新建Vue实例-->
<div id="app">
    <div class="main">
        <table cellspacing="0">
            <thead>
            <tr>
                <th>{{message}}</th>
                <th>标题2</th>
                <th>标题3</th>
                <th>标题4</th>
                <th>标题5</th>
                <th>标题6</th>
                <th>标题7</th>
                <th>标题8</th>
                <th>标题9</th>
                <th>标题10</th>
                <th>标题11</th>
                <th>标题12</th>
                <th>标题13</th>
                <th>标题14</th>
                <th>标题15</th>
            </tr>
            </thead>
            <tbody>
            <!--vue的 v-for的遍历-->
            <tr v-for="(item,index) in 50" :key="index">
                <td>demo1</td>
                <td>demo2</td>
                <td>demo3</td>
                <td>demo4</td>
                <td>demo5</td>
                <td>demo6</td>
                <td>demo7</td>
                <td>demo8</td>
                <td>demo9</td>
                <td>demo10</td>
                <td>demo11</td>
                <td>demo12</td>
                <td>demo13</td>
                <td>demo14</td>
                <td>demo15</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
<!--把<div id="app></div>和这个标签里面包含的所有DOM都实例化成了一个JS对象, 这个对象就是app-->
<script>
    var app=new Vue({
        el:'#app',
        data:{
           message:'hello'
        },
        methods:{
            clickButton:function(){
                this.my_data = "Wow! I'm changed!"
             }
        }
    })
</script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值