当前位置:网站首页>一篇文章带你了解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
边栏推荐
- High availability cluster deployment of jumpserver: (6) deployment of SSH agent module Koko and implementation of system service management
- It's so embarrassing, fans broke ten thousand, used for a year!
- What is the difference between data scientists and machine learning engineers? - kdnuggets
- 在大规模 Kubernetes 集群上实现高 SLO 的方法
- git rebase的時候捅婁子了,怎麼辦?線上等……
- Not long after graduation, he earned 20000 yuan from private work!
- Didi elasticsearch cluster cross version upgrade and platform reconfiguration
- 采购供应商系统是什么?采购供应商管理平台解决方案
- DevOps是什么
- 合约交易系统开发|智能合约交易平台搭建
猜你喜欢
What is the side effect free method? How to name it? - Mario
容联完成1.25亿美元F轮融资
ipfs正舵者Filecoin落地正当时 FIL币价格破千来了
How to encapsulate distributed locks more elegantly
一篇文章带你了解CSS3圆角知识
Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
如何将数据变成资产?吸引数据科学家
至联云分享:IPFS/Filecoin值不值得投资?
Face to face Manual Chapter 16: explanation and implementation of fair lock of code peasant association lock and reentrantlock
向北京集结!OpenI/O 2020启智开发者大会进入倒计时
随机推荐
The choice of enterprise database is usually decided by the system architect - the newstack
Why do private enterprises do party building? ——Special subject study of geek state holding Party branch
Deep understanding of common methods of JS array
5.4 static resource mapping
助力金融科技创新发展,ATFX走在行业最前列
教你轻松搞懂vue-codemirror的基本用法:主要实现代码编辑、验证提示、代码格式化
至联云解析:IPFS/Filecoin挖矿为什么这么难?
Common algorithm interview has been out! Machine learning algorithm interview - KDnuggets
你的财务报告该换个高级的套路了——财务分析驾驶舱
加速「全民直播」洪流,如何攻克延时、卡顿、高并发难题?
Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
容联完成1.25亿美元F轮融资
What is the difference between data scientists and machine learning engineers? - kdnuggets
合约交易系统开发|智能合约交易平台搭建
6.5 request to view name translator (in-depth analysis of SSM and project practice)
多机器人行情共享解决方案
做外包真的很难,身为外包的我也无奈叹息。
How long does it take you to work out an object-oriented programming interview question from Ali school?
如何将数据变成资产?吸引数据科学家
IPFS/Filecoin合法性:保护个人隐私不被泄露