<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>设置表格的边框</title>
<style type="text/css">
.t{
border: 1px gray solid;
border-spacing: 0px;
border-collapse: collapse;
}
.t td{
border: 1px gray solid;
padding: 5px;
}
.t th{
border: 1px gray solid;
padding: 5px;
}
</style>
</head>
<body>
<table class="t">
<caption>学生信息</caption>
<thead>
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>出生日期</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td>001</td>
<td>魏安复</td>
<td>男</td>
<td>2012-12-12</td>
</tr>
<tr>
<th>2</th>
<td>002</td>
<td>杜子腾</td>
<td>女</td>
<td>2011-11-11</td>
</tr>
<tr>
<th>3</th>
<td>003</td>
<td>史珍湘</td>
<td>女</td>
<td>2010-10-10</td>
</tr>
<tr>
<th>4</th>
<td>004</td>
<td>梅读</td>
<td>女</td>
<td>2009-10-10</td>
</tr>
<tr>
<th>5</th>
<td>005</td>
<td>赖月金</td>
<td>男</td>
<td>2008-01-01</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>总计</th>
<th colspan="4">5条数据</th>
</tr>
</tfoot>
</table>
</body>
</html>
不设置任何样式的效果图
加上 .t{
border: 1px gray solid;
}
.t td{
border: 1px gray solid;
}
.t th{
border: 1px gray solid;
}
效果图:
默认分离:
.t{
border: 1px gray solid;
border-spacing: 0px;
border-collapse: separate;//默认就是分离的
}
.t td{
border: 1px gray solid;
}
.t th{
border: 1px gray solid;
}
.t{
border: 1px gray solid;
border-spacing: 0px;//单元格间距为0px
border-collapse: collapse;//=改为合并
}
.t td{
border: 1px gray solid;
}
.t th{
border: 1px gray solid;
}
效果图:单元格之间的线只有1根了,变细了
修改成下面的代码
.t td{
border: 1px gray solid;
padding: 5px;
}
.t th{
border: 1px gray solid;
padding: 5px;
}
效果图
表格宽度是自动的,如果其中单元格内容很长,会自动变宽,不受设置的表格宽度限制
.t{
border: 1px gray solid;
border-spacing: 0px;
border-collapse: collapse;
width: 500px;
table-layout: fixed;//设置这个属性,表格长度固定了
}
加上下面的代码(设置表格列样式)
//设置学号这一列
th+td{
text-align: center;
}
//设置性别这一列
th+td+td+td{
text-align: center;
background-color: red;
}