首页 > 其他 > 详细

表格单元平分线绘制

时间:2020-11-02 16:38:44      阅读:26      评论:0      收藏:0      [点我收藏+]

思路:在单个单元格内,通过canvas将显示的内容进行划分

1.html代码

<table cellspacing="0" cellpadding="0" border=1>
      <tr>
          <th class="first">
              <div class="title1">水果</div>
              <div class="title2">季节</div>
             <canvas id="drawTh"></canvas>
          </th>
          <th>苹果</th>
          <th>梨子</th>
      </tr>
      <tr>
          <td>秋季</td>
          <td>100</td>
          <td>200</td>
      </tr>
      <tr>
          <td>冬季</td>
          <td>10</td>
          <td>20</td>
      </tr>
</table>

2.css代码

        table{
            width: 400px;
            height: 120px;
       text-align: center;
     }
        .title1,.title2{
            position: absolute;
            display: flex;
        }
        .title1{
            top: 20%;
            right: 15%;
        }
        .title2{
            bottom: 20%;
            left: 15%;
        }
        #drawTh{
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            width: 100%;
            height: 100%;
        }
        th[class=first]{
            height: 40px;
            width: 100px;
            min-width: 100px!important;
            position: relative;
        }

3.js代码

   //绘制中分线
    var context = document.getElementById(drawTh).getContext(2d);
    console.log(context)
    // 设置线条的颜色
    context.strokeStyle = #808080;
    // 设置线条的宽度
    context.lineWidth = 5;
    // 绘制直线
    context.beginPath();
    // 起点
    context.moveTo(0, 0);
    // 终点
    context.lineTo(420, 207);
    context.closePath();
    context.stroke();

4.效果图

技术分享图片

表格单元平分线绘制

原文:https://www.cnblogs.com/zhuguanke/p/13914554.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!