当前位置:网站首页>一篇文章带你了解HTML表格及其主要属性介绍
一篇文章带你了解HTML表格及其主要属性介绍
2020-11-06 20:48:00 【Python进阶者】
一、定义一个HTML表格
使用标签定义HTML表格。
标签定义表中的每一行使用。使用标签定义表头。默认情况下,表标题是粗体和居中的。一个表的数据/单元使用 标签定义。
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
注意: 元素是表的数据容器。它们可以包含所有的HTML元素; 文本、图像、列表、其他表格等。
1. HTML表格 - 添加边框
如果不指定表的边框,则将不显示边框。
使用CSS设置表格的边框如下:
<style>
table, th, td {
border: 1px solid black;
}
</style>
记住为表和表单元格定义边框。
2. HTML 表格 - 折叠边框
如果你想要的边框折叠成一个边框,添加CSS border-collaps边框属性:
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse; /*折叠边框*/
}
</style>
3. HTML 表格 - 添加单元格填充(padding)
单元格填充(padding)指定单元格内容及其边框之间的空间。
如果不指定填充(padding),则将显示表单元格而不填充(padding)。
设置填充,使用css padding属性:
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px; /* 设置边距*/
}
</style>
4. HTML表格 - 左对齐标题
默认情况下,表标题是粗体和居中的。
左对齐的表格标题,使用CSS text-align属性:
th {
text-align: left;
}
5. HTML表格 - 添加边框间距
边框间距指定单元格之间的空间。
设置一个表空间的边界,使用CSS border-spacing属性:
table {
border-spacing: 15px; /*添加边框间距*/
}
注意:如果表已经是collapsed折叠边框,边框间距没有影响。
6. HTML表格 单元格跨多列
使表格单元格跨越多个列,使用colspan属性:
<table style="width:100%">
<tr>
<th>姓名</th>
<th colspan="2">电话</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>55577854</td>
<td>55577855</td>
</tr>
</table>
7. HTML表中 - 单元格跨多行
使表格单元格跨多个行,使用rowspan属性:
<table style="width:100%">
<tr>
<th>姓名:</th>
<td>比尔</td>
</tr>
<tr>
<th rowspan="2">电话:</th>
<td>55577854</td>
</tr>
<tr>
<td>55577855</td>
</tr>
</table>
8. HTML表格 - 添加标题
若要向表添加标题,请使用`标签:
<table style="width:100%">
<caption>每月储蓄</caption> <!--标题-->
<tr>
<th>月</th>
<th>储蓄</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
注意:` 标签必须立即插入在``标签之后。
二、项目
为表格指定一个特殊样式
为表格指定一个特殊样式, 添加一个 id 属性:
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
现在您可以为这个表定义一个特殊的样式:
table#t01 {
width: 100%;
background-color: #f1f1c1;
border: 2px solid black;
}
添加更多样式:
table#t01 tr:nth-child(even) {
background-color: #eee;
}
table#t01 tr:nth-child(odd) {
background-color: #fff;
}
table#t01 th {
color: white;
background-color: black;
}
小总结
标签 | 描述 |
---|---|
<table> | 定义表格 |
<th> | 定义表中的头单元格 |
<tr> | 定义表中的一行 |
<td> | 定义表中的单元格 |
<caption> | 定义一个表格标题 |
<colgroup> | 指定表格中一组或多个列的格式. |
<col> | 指定列内每个列的属性用. <colgroup> 元素 |
<thead> | 使用表中的标题内容分组 |
<tbody> | 将身体内容分组在一个表中 |
属性 | 描述 |
---|---|
border |
属性定义一个边框 |
border-collapse |
定义折叠单元格边框的属性 |
padding |
添加到单元格中的填充 |
text-align |
对齐单元格文本 |
border-spacing |
设置单元格之间的间距 |
colspan |
使单元格跨越多个列 |
rowspan |
使单元格跨越多行 |
id |
唯一表示一个表格 |
三、总结
本文主要介绍了HTML表格,对表格中主要的属性进行了详细的介绍。对遇到的问题进行详细的解答。方便大家表格的标签的了解。希望对大家的学习有帮助。
想学习更多Python网络爬虫与数据挖掘知识,可前往专业网站:http://pdcfighting.com/
版权声明
本文为[Python进阶者]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4521128/blog/4683735
边栏推荐
- Vuejs development specification
- Existence judgment in structured data
- Summary of common algorithms of linked list
- 至联云解析:IPFS/Filecoin挖矿为什么这么难?
- Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
- 多机器人行情共享解决方案
- 6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
- Leetcode's ransom letter
- Using consult to realize service discovery: instance ID customization
- 一篇文章带你了解CSS 渐变知识
猜你喜欢
ES6学习笔记(四):教你轻松搞懂ES6的新增语法
大数据应用的重要性体现在方方面面
Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
Python自动化测试学习哪些知识?
助力金融科技创新发展,ATFX走在行业最前列
Do not understand UML class diagram? Take a look at this edition of rural love class diagram, a learn!
How to select the evaluation index of classification model
Using Es5 to realize the class of ES6
中国提出的AI方法影响越来越大,天大等从大量文献中挖掘AI发展规律
从海外进军中国,Rancher要执容器云市场牛耳 | 爱分析调研
随机推荐
华为云“四个可靠”的方法论
Python crawler actual combat details: crawling home of pictures
I think it is necessary to write a general idempotent component
熬夜总结了报表自动化、数据可视化和挖掘的要点,和你想的不一样
Installing the consult cluster
Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
深度揭祕垃圾回收底層,這次讓你徹底弄懂她
6.3 handlerexceptionresolver exception handling (in-depth analysis of SSM and project practice)
Didi elasticsearch cluster cross version upgrade and platform reconfiguration
你的财务报告该换个高级的套路了——财务分析驾驶舱
关于Kubernetes 与 OAM 构建统一、标准化的应用管理平台知识!(附网盘链接)
一篇文章带你了解CSS 分页实例
In depth understanding of the construction of Intelligent Recommendation System
教你轻松搞懂vue-codemirror的基本用法:主要实现代码编辑、验证提示、代码格式化
6.6.1 localeresolver internationalization parser (1) (in-depth analysis of SSM and project practice)
100元扫货阿里云是怎样的体验?
How long does it take you to work out an object-oriented programming interview question from Ali school?
Natural language processing - wrong word recognition (based on Python) kenlm, pycorrector
PN8162 20W PD快充芯片,PD快充充电器方案
I've been rejected by the product manager. Why don't you know