**表格标签(设置表格的宽高不能限定每个单元格大小都一样):**
<table>
<tr> //表示一行
<th></th> //表示一个单元格,一般用于表头格,默认居中加黑
<td></td> //表示一个单元格
</tr>
</table>
**table属性:**
border
加表格线和边框
<table border="1px">
width
height
<table border="1px" width="400px" height="200px"/>
cellpadding
内容距边框的距离
cellspacing
边框的宽度大小
<table border="1px" cellpadding="10px" cellspacing="0px"/>
frame
规定外侧边框的哪个部分是可见的
void、above、below、hsides、lhs、rhs、vsides、box、border
rules
规定内侧边框的哪个部分是可见的
none、groups、rows、cols、all
**table的css属性:**
table-layout: fixed;
automatic 默认。列宽度由单元格内容设定。
fixed 列宽由表格宽度和列宽度设定。更快
border-collapse: collapse;
separate 默认值。边框会被分开。不会忽略 border-spacing 和 empty-cells 属性。
collapse 如果可能,边框会合并为一个单一的边框。会忽略 border-spacing 和 empty-cells 属性。
**设置单元格大小:**
设置行的高度即单元格高度
<tr
height="50px"
align='right、left、center、justify、char'
char='character' 规定根据哪个字符来进行文本对齐。
charoff='number' 规定第一个对齐字符的偏移量。不支持
、 valign='top、middle、bottom、baseline' 规定元素中内容的垂直对齐
></tr>
设置第一个单元格的宽度(即标题单元格),即列宽已确定
<th
width="200px"
align='right、left、center、justify、char'
、 valign='top、middle、bottom、baseline' 规定元素中内容的垂直对齐
>网易</th>
<th width="200px">qq</th>
<th width="200px">咪咕</th>
<th width="200px">酷狗</th>
设置普通单元格
<td
width="200px"
align='right、left、center、justify、char'
、 valign='top、middle、bottom、baseline' 规定元素中内容的垂直对齐
>网易
</td>
**扩展标签**
(1)分别用来对表头、表内容、表尾进行分组,内部都必须有tr标签
thead、tbody、tfoot
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
标签属性:
align:right、left、center、justify、char 定义元素中内容的对齐方式。
char: character 规定根据哪个字符来进行文本对齐。
charoff: number 规定第一个对齐字符的偏移量。不支持
、 valign:top、middle、bottom、baseline 规定元素中内容的垂直对齐
(2)对每列进行整体样式设置
必须在tr元素内部规定td元素。
方式一:colgroup(必须包含在table元素内,按个数从左往右设置每列样式)
<table>
<colgroup
span='n' 当前colgroup同时设置几个列,不写,默认一个colgroup设置一个列
align='right、left、center、justify、char'
width='npx' 列的宽度
char='character' 规定根据哪个字符来进行文本对齐。
charoff='number' 规定第一个对齐字符的偏移量。不支持
、 valign='top、middle、bottom、baseline' 规定元素中内容的垂直对齐
>
</colgroup>
</table>
方式二:col(必须包含在table或colgroup元素内,按个数从左往右设置每列样式)
<table>
<colgroup>
<col
span='n' 当前colgroup同时设置几个列,不写,默认一个colgroup设置一个列
align='right、left、center、justify、char'
width='npx' 列的宽度
char='character' 规定根据哪个字符来进行文本对齐。
charoff='number' 规定第一个对齐字符的偏移量。不支持
、 valign='top、middle、bottom、baseline' 规定元素中内容的垂直对齐
/>
<col align="left" />
<col align="right" />
</colgroup>
</table>
(3)在表格上定义标题
caption标签必须紧随 table 标签之后,默认居中
<table border="1">
<caption
align='right、left、top、bottom'
>Monthly savings</caption>
</table>
代码实例
<html>
<head>
<title>表格标签学习</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<h3 align="center">表格标签学习</h3>
<hr size="30" color="aquamarine"/>
<table border="1px" cellpadding="10px" cellspacing="0px"/>
<tr height="50px"><!--一个tr表示一行-->
<th width="200px">网易</th> <!--一个td声明了一个单元格-->
<th width="200px">qq</th>
<th width="200px">咪咕</th>
<th width="200px">酷狗</th>
</tr>
<tr height="50px">
<td>云</td>
<td>乐</td>
<td>音</td>
<td>dog</td>
</tr>
<tr height="50px">
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
</html>