html添加斜线

本文介绍两种使用CSS技巧来实现表格中单元格的对角线效果的方法。第一种方法利用div的上边框和左边框创建对角线样式;第二种方法则通过CSS伪元素:before,并结合旋转变换来实现。这两种方法为网页设计提供了灵活的选择。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、利用div的上边框和左边框

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用div+css模拟表格对角线</title>
<style type="text/css">
table{ border-collapse:collapse;border:1px #525152 solid;width:90%;margin:0 auto;margin-top:100px;}
th,td{border:1px solid #525152;text-align:center;font-size:12px;line-height:30px;background:#C6C7C6;}
th{background:#D6D3D6;}
/*模拟对角线*/
.out{
   border-top:25em #D6D3D6 solid;/*上边框宽度等于表格第一行行高*/
   border-left:80px#BDBABD solid;/*左边框宽度等于表格第一行第一格宽度*/
   position:relative;/*让里面的两个子容器绝对定位*/
}
b{font-style:normal;display:block;position:absolute;top:-23em;left:-75px;width:80px;}
em{font-style:normal;display:block;position:absolute;top:-40px;left:-90px;width:80px;}
.assessDetail td{background-color: #FFF;}
</style>
</head>
<body>
<table>
  <tr>
    <th style="width:80px;" >
  <div class="out">
<b>内容及标准</b>
<em>考核对象</em>
</div>
</th>
    <th>年级</th>
    <th>班级</th>
    <th>成绩</th>
    <th>班级均分</th>
    <th style="width:80px;" rowspan="3">总分</th>
  </tr>
  <tr>
  <td></td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr>
  <td></td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr class="assessDetail">
  <td>部门</td>
  <td>1</td>
  <td>2</td>
  <td>3</td>
  <td>4</td>
  <td>5</td>
  </tr>
  <tr class="assessDetail">
  <td>办公室</td>
  <td>1</td>
  <td>2</td>
  <td>3</td>
  <td>4</td>
  <td>5</td>
  </tr>
  <tr>
  </tr>
</table>
</body>
</html>


2、利用伪类

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>td加斜线</title>
<style>
table{
border-collapse:collapse;
}
table,tr,td{
border:1px solid black;
}
td{
width:100px;/*这里需要自己调整,根据自己的需求调整宽度*/
height:50px;/*这里需要自己调整,根据自己的需求调整高度*/
position: relative;
}
td[class=first]:before{
content: "";
position: absolute;
width: 1px;
height:114px;/*这里需要自己调整,根据td的宽度和高度*/
top:0;
left:0;
background-color: black;
display: block;
transform: rotate(-63deg);/*这里需要自己调整,根据线的位置*/
transform-origin: top;
}

</style>
</head>
<body>
<table>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
<tr>
<td class="first"></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值