HTML表格
来源:互联网 发布:it书籍 编辑:程序博客网 时间:2024/06/05 02:55
1、表格
<table>定义表格
<tr>table row定义表格行
<td>table data 定义表格内容
例子:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="form/html; charset=utf-8" />
<style type="text/css">
p {color:red}
h1 {color:blue}
</style>
</head>
<body>
<h1>创建一个两行三列的表格</h1>
<table border="15">
<tr>
<td>34</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td>340</td>
<td>74</td>
<td>03</td>
</tr>
</table>
</body>
</html>
结果:
2、表格的边框
如果不定义边框则表格没有边框,用border定义边框, 如上面例子所示
3、表格表头用<th>标签表示
大多数浏览器会把表头显示为粗体居中的文本
<body>
<h1>创建一个两行三列的表格</h1>
<table border="15">
<tr>
<th>heading</th>
<th>another heading</th>
<th>other heading</th>
</tr>
<tr>
<td>34</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td>340</td>
<td>74</td>
<td>03</td>
</tr>
</table>
</body>
结果
4、表格空单元
<body>
<h1>创建一个两行三列的表格</h1>
<table border="15">
<tr>
<th>heading</th>
<th>another heading</th>
<th>other heading</th>
</tr>
<tr>
<td>34</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td>74</td>
<td>03</td>
</tr>
</table>
</body>
结果:
5、用<caption>标签表示标题
<body>
<h1>创建一个两行三列的表格</h1>
<table border="15">
<caption>我是表格</caption>
<tr>
<th>heading</th>
<th>another heading</th>
<th>other heading</th>
</tr>
<tr>
<td>34</td>
<td>4</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td>74</td>
<td>03</td>
</tr>
</table>
</body>
6、跨两行或跨两列
<body>
<h1>创建一个两行三列的表格</h1>
<table border="15">
<caption>我是表格</caption>
<tr>
<th>heading</th>
<th colspan="2">another heading</th> #跨两列
</tr>
<tr>
<th rowspan="2">数字</th> #跨两行
<td>4</td>
<td>3</td>
</tr>
<tr>
<td>74</td>
<td>03</td>
</tr>
</table>
</body>
7、表格内的标签:列表用<ul> 列出的内容用:<li>
<body>
<h1>创建一个三行三列的表格</h1>
<table border="5">
<caption>我是表格</caption>
<tr>
<th>another heading</th>
<th colspan="2">数字</th>
</tr>
<tr>
<td>
你是?<br/>
程序猿?
</td>
<td>喜欢吃:
<ul>
<li>香蕉</li>
<li>苹果</li>
<li>葡萄</li>
</ul>
</td>
</tr>
<tr>
<td>统计水果的量表:
<table border="1">
<tr>
<th>水果名称</th>
<td colspan="2">数量</td>
</tr>
<tr>
<td>香蕉</td>
<td>2</td>
<th rowspan="3">都好吃</th>
</tr>
<tr>
<td>苹果</td>
<td>22</td>
</tr>
<tr>
<td>香蕉</td>
<td>233</td>
</tr>
</table>
</td>
<td>
好!
</td>
</tr>
</table>
</body>
结果:
8、单元格边距和间距
边距 cell padding
间距 cell sapcing
<body>
<table border="5">
<caption>没有间距 边距</caption>
<tr>
<td>29</td>
<td>2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
<table border="5" cellpadding="10">
<caption>边距 cellpadding</caption>
<tr>
<td>29</td>
<td>2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
<table border="5" cellspacing="10">
<caption>间距 cellspacing</caption>
<tr>
<td>29</td>
<td>2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
</body>
结果:
9、表格添加背景颜色和图像
背景颜色: bgcolor
背景图片: background
<body>
<table border="5" cellpadding="10" bgcolor="red">
<caption>边距 cellpadding</caption>
<tr>
<td>29</td>
<td>2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
<table border="5" cellpadding="10" background="taylor.jpg">
<caption>边距 cellpadding</caption>
<tr>
<td>29</td>
<td>2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
</body>
结果:
10、单元格背景颜色和图片
背景颜色: bgcolor
背景图片: background
<body><table border="5" cellpadding="10">
<caption>哈哈</caption>
<tr>
<td bgcolor="red">29</td>
<td background="taylor.jpg">2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
</body>
结果
11、单元格居中 左对齐 右对齐
<body>
<table width="400" border="5" cellpadding="10">
<caption>哈哈</caption>
<tr>
<td align="right">29</td>
<td align="right">2</td>
</tr>
<tr>
<td align="left">26</td>
<td align="left">29</td>
</tr>
</table>
</body>
12、单元格框架(frame)属性
box 仅保留外框 above 仅保留上边框 below 仅保留下边看 hsides 保留上下边框 vsides 保留左右边框
以box为例
<body>
<table frame="box">
<caption>哈哈</caption>
<tr>
<td>29</td>
<td>2</td>
</tr>
<tr>
<td>26</td>
<td>29</td>
</tr>
</table>
</body>
结果
表格描述<table>定义表格<caption>定义表格标题。<th>定义表格的表头。<tr>定义表格的行。<td>定义表格单元。<thead>定义表格的页眉。<tbody>定义表格的主体。<tfoot>定义表格的页脚。<col>定义用于表格列的属性。<colgroup>定义表格列的组。
- html 表格
- HTML 表格
- HTML表格
- HTML表格
- Html:表格
- HTML表格
- HTML 表格
- HTML表格
- html 表格
- HTML表格
- html表格
- html表格
- HTML表格
- html 表格
- HTML:表格
- html 表格
- HTML表格
- HTML表格
- Java中protected语义解释
- Android Studio解决refreshing gradle project
- iPhone7如“7”而至曝光八大新功能,骚扰拦截成亮点
- Apple Watch 2 传闻大汇总 你想知道的都在这里
- 预告:解析虚拟现实中的位置追踪技术 | 硬创公开课
- HTML表格
- 用户画像系统应用与技术解析
- 【C语言】编译执行
- 内置对象(out,resquest,response)及对话session之间的关系
- C++进阶—>子类、父类、父父类间虚函数调用详解
- 极光推送,相关问题
- arduino学习笔记3 蜂鸣器
- ansible学习笔记(二)
- 可凝儿DIO系列 滑溜溜柔顺丝滑洗发露