一、基本表格:

表格标记<table>,行标记<tr>,单元格标记<td>

基本语法:

<table>
<tr>
<td>单元格内文字</td>
<td>单元格内文字</td>
......
</tr>
<tr>
<td>单元格内文字</td>
<td>单元格内文字</td>
......
</tr>
......
</table>

示例代码:

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>第9章</title>
</head>
<style type="text/css">
body {
font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
background: #E6EAE9;
} a {
color: #c75f3e;
} #mytable {
width: 700px;
padding: 0;
margin: 0;
} caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
} th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
} th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
} td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size: 11px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
} td.alt {
background: #F5FAFA;
color: #797268;
} th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff url(images/bullet1.gif) no-repeat;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
} th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa url(images/bullet2.gif) no-repeat;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
}
</style>
<body>
<table id="mytable" cellspacing="0" summary="The technical specifications of the Apple PowerMac G5 series">
<caption>The technical specifications of the Apple PowerMac G5 series</caption>
<tr>
<th scope="col" abbr="Configurations">设置</th>
<th scope="col" abbr="Dual 1.8">1.8GHz</th>
<th scope="col" abbr="Dual 2">2GHz</th>
<th scope="col" abbr="Dual 2.5">2.5GHz</th>
</tr>
<tr>
<th scope="row" abbr="Model" class="spec">lipeng</th>
<td>M9454LL/A</td>
<td>M9455LL/A</td>
<td>M9457LL/A</td>
</tr>
<tr>
<th scope="row" abbr="G5 Processor" class="specalt">mapabc</th>
<td class="alt">Dual 1.8GHz PowerPC G5</td>
<td class="alt">Dual 2GHz PowerPC G5</td>
<td class="alt">Dual 2.5GHz PowerPC G5</td>
</tr>
<tr>
<th scope="row" abbr="Frontside bus" class="spec">Lennvo</th>
<td>900MHz per processor</td>
<td>1GHz per processor</td>
<td>1.25GHz per processor</td>
</tr>
<tr>
<th scope="row" abbr="L2 Cache" class="specalt">Black</th>
<td class="alt">512K per processor</td>
<td class="alt">512K per processor</td>
<td class="alt">512K per processor</td>
</tr>
</table>
</body>
</html>

二、让表格没有凹凸感

没有样式的情况下,表格边框是凹凸的,可以使用cellspacing和cellpadding来取消凹凸感。cellspacing是td与td之间的距离,而cellpadding是单元格内部内容与单元格边界之间的空白距离的大小。

例如:

 <table border="1" cellpadding="0" cellspacing="0">
<tr>
<th>单元格内的标题</th>
<th>单元格内的标题</th>
</tr>
<tr>
<td>单元格内的文字</td>
<td>单元格内的文字</td>
</tr>
<tr>
<td>单元格内的文字</td>
<td>单元格内的文字</td>
</tr>
</table>

三、添加表头th

 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta name="format-detection" content="telephone=no" />
<title>第9章</title>
</head>
<body>
<table cellspacing="0">
<tr>
<th>序号</th>
<th>歌曲名</th>
<th>演唱</th>
</tr>
<tr>
<th>01</th>
<td>小苹果</td>
<td>筷子兄弟</td>
</tr>
<tr>
<th>02</th>
<td>匆匆那年</td>
<td>王菲</td>
</tr>
<tr>
<th>03</th>
<td>喜欢你</td>
<td>G.E.M.邓紫棋</td>
</tr>
<tr>
<th>04</th>
<td>当你老了</td>
<td>莫文蔚</td>
</tr>
</table>
<body>
</body>
</html>

为了更进一步区分表头与内容,对表格进行样式设计,顺便添加<thead>,<tbody>,<tfoot>标签为表格完善结构,更进一步区别不同部分:

 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta name="format-detection" content="telephone=no" />
<title>第9章</title>
<style type="text/css">
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
} td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size: 11px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
thead th {
color: red;
}
tfoot th {
color: blue;
}
</style>
</head>
<body>
<table cellspacing="0">
<thead>
<tr>
<th>序号</th>
<th>歌曲名</th>
<th>演唱</th>
</tr>
</thead>
<tbody>
<tr>
<th>01</th>
<td>小苹果</td>
<td>筷子兄弟</td>
</tr>
<tr>
<th>02</th>
<td>匆匆那年</td>
<td>王菲</td>
</tr>
<tr>
<th>03</th>
<td>喜欢你</td>
<td>G.E.M.邓紫棋</td>
</tr>
<tr>
<th>04</th>
<td>当你老了</td>
<td>莫文蔚</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>序号</th>
<th>歌曲名</th>
<th>演唱</th>
</tr>
</tfoot>
</table>
<body>
</body>
</html>

四、不规则表格

colspan 属性规定单元格可横跨的列数。rowspan 属性规定单元格可横跨的行数。

 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta name="format-detection" content="telephone=no" />
<title>第9章</title>
<style type="text/css">
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
} td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size: 11px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
</style>
</head>
<body>
<table cellspacing="0">
<thead>
<tr>
<th>序号</th>
<th>歌曲名</th>
<th>演唱</th>
</tr>
</thead>
<tbody>
<tr>
<th>01</th>
<td>小苹果</td>
<td>筷子兄弟</td>
</tr>
<tr>
<th>02</th>
<td>匆匆那年</td>
<td colspan="1" rowspan="2">王菲</td>
</tr>
<tr>
<th>03</th>
<td>致青春</td>
</tr>
<tr>
<th>04</th>
<td>喜欢你</td>
<td>G.E.M.邓紫棋</td>
</tr>
<tr>
<th>05</th>
<td>当你老了</td>
<td>莫文蔚</td>
</tr>
<tr>
<th>06</th>
<td colspan="2" rowspan="1">群星演唱最炫小苹果</td>
</tr>
</tbody>
</table>
<body>
</body>
</html>

五、几种常见表格设计

1、圆角表格

 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta name="format-detection" content="telephone=no" />
<title>第9章</title> </head>
<body>
<style> body {
width: 600px;
margin: 40px auto;
font-family: 'trebuchet MS', 'Lucida sans', Arial;
font-size: 14px;
color: #444;
} table {
*border-collapse: collapse; /* IE7 and lower */
border-spacing: 0;
width: 100%;
} .bordered {
border: solid #ccc 1px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 1px 1px #ccc;
-moz-box-shadow: 0 1px 1px #ccc;
box-shadow: 0 1px 1px #ccc;
} .bordered tr:hover {
background: #fbf8e9;
-o-transition: all 0.1s ease-in-out;
-webkit-transition: all 0.1s ease-in-out;
-moz-transition: all 0.1s ease-in-out;
-ms-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
} .bordered td, .bordered th {
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
padding: 10px;
text-align: left;
} .bordered th {
background-color: #dce9f9;
background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));
background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);
background-image: -moz-linear-gradient(top, #ebf3fc, #dce9f9);
background-image: -ms-linear-gradient(top, #ebf3fc, #dce9f9);
background-image: -o-linear-gradient(top, #ebf3fc, #dce9f9);
background-image: linear-gradient(top, #ebf3fc, #dce9f9);
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
-moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;
box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
border-top: none;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
} .bordered td:first-child, .bordered th:first-child {
border-left: none;
} .bordered th:first-child {
-moz-border-radius: 6px 0 0 0;
-webkit-border-radius: 6px 0 0 0;
border-radius: 6px 0 0 0;
} .bordered th:last-child {
-moz-border-radius: 0 6px 0 0;
-webkit-border-radius: 0 6px 0 0;
border-radius: 0 6px 0 0;
} .bordered th:only-child{
-moz-border-radius: 6px 6px 0 0;
-webkit-border-radius: 6px 6px 0 0;
border-radius: 6px 6px 0 0;
} .bordered tr:last-child td:first-child {
-moz-border-radius: 0 0 0 6px;
-webkit-border-radius: 0 0 0 6px;
border-radius: 0 0 0 6px;
} .bordered tr:last-child td:last-child {
-moz-border-radius: 0 0 6px 0;
-webkit-border-radius: 0 0 6px 0;
border-radius: 0 0 6px 0;
} </style>
<table class="bordered">
<caption>金曲排行</caption>
<thead>
<tr>
<th>序号</th>
<th>歌曲名</th>
<th>演唱</th>
<th>人气</th>
</tr>
</thead>
<tbody>
<tr>
<th>01</th>
<td>小苹果</td>
<td>筷子兄弟</td>
<td>120093</td>
</tr>
<tr>
<th>02</th>
<td>匆匆那年</td>
<td colspan="1" rowspan="2">王菲</td>
<td colspan="1" rowspan="2">38490</td>
</tr>
<tr>
<th>03</th>
<td>致青春</td>
</tr>
<tr>
<th>04</th>
<td>喜欢你</td>
<td>G.E.M.邓紫棋</td>
<td>37449</td>
</tr>
<tr>
<th>05</th>
<td>当你老了</td>
<td>莫文蔚</td>
<td>93947</td>
</tr>
<tr>
<th>06</th>
<td colspan="2" rowspan="1">群星演唱最炫小苹果</td>
<td>93984</td>
</tr>
</tbody>
</table>
<body>
</body>
</html>

2、条纹表格

 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta name="format-detection" content="telephone=no" />
<title>第9章</title> </head>
<body>
<style>
body {
width: 600px;
margin: 40px auto;
font-family: 'trebuchet MS', 'Lucida sans', Arial;
font-size: 14px;
color: #444;
} table {
*border-collapse: collapse; /* IE7 and lower */
border-spacing: 0;
width: 100%;
} .zebra td, .zebra th {
padding: 10px;
border-bottom: 1px solid #f2f2f2;
} .zebra tbody tr:nth-child(even) {
background: #f5f5f5;
-webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
-moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;
box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
} .zebra th {
text-align: left;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
border-bottom: 1px solid #ccc;
background-color: #eee;
background-image: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#eee));
background-image: -webkit-linear-gradient(top, #f5f5f5, #eee);
background-image: -moz-linear-gradient(top, #f5f5f5, #eee);
background-image: -ms-linear-gradient(top, #f5f5f5, #eee);
background-image: -o-linear-gradient(top, #f5f5f5, #eee);
background-image: linear-gradient(top, #f5f5f5, #eee);
} .zebra th:first-child {
-moz-border-radius: 6px 0 0 0;
-webkit-border-radius: 6px 0 0 0;
border-radius: 6px 0 0 0;
} .zebra th:last-child {
-moz-border-radius: 0 6px 0 0;
-webkit-border-radius: 0 6px 0 0;
border-radius: 0 6px 0 0;
} .zebra th:only-child{
-moz-border-radius: 6px 6px 0 0;
-webkit-border-radius: 6px 6px 0 0;
border-radius: 6px 6px 0 0;
} .zebra tfoot td {
border-bottom: 0;
border-top: 1px solid #fff;
background-color: #f1f1f1;
} .zebra tfoot td:first-child {
-moz-border-radius: 0 0 0 6px;
-webkit-border-radius: 0 0 0 6px;
border-radius: 0 0 0 6px;
} .zebra tfoot td:last-child {
-moz-border-radius: 0 0 6px 0;
-webkit-border-radius: 0 0 6px 0;
border-radius: 0 0 6px 0;
} .zebra tfoot td:only-child{
-moz-border-radius: 0 0 6px 6px;
-webkit-border-radius: 0 0 6px 6px
border-radius: 0 0 6px 6px
} </style>
<table class="zebra">
<caption>金曲排行</caption>
<thead>
<tr>
<th>序号</th>
<th>歌曲名</th>
<th>演唱</th>
<th>人气</th>
</tr>
</thead>
<tfoot>
<tr>
<td>&nbsp;</td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
<tbody>
<tr>
<td>01</td>
<td>小苹果</td>
<td>筷子兄弟</td>
<td>1200903</td>
</tr>
<tr>
<td>02</td>
<td>匆匆那年</td>
<td>王菲</td>
<td>138490</td>
</tr>
<tr>
<td>03</td>
<td>致青春</td>
<td>王菲</td>
<td>138489</td>
</tr>
<tr>
<td>04</td>
<td>喜欢你</td>
<td>G.E.M.邓紫棋</td>
<td>137449</td>
</tr>
<tr>
<td>05</td>
<td>当你老了</td>
<td>莫文蔚</td>
<td>93947</td>
</tr>
<tr>
<td>06</td>
<td colspan="2" rowspan="1">群星演唱最炫小苹果</td>
<td>93984</td>
</tr>
</tbody>
</table>
<body>
</body>
</html>

HTML系列(八):表格的更多相关文章

  1. 微软云平台windows azure入门系列八课程

    微软云平台windows azure入门系列八课程: Windows Azure入门教学系列 (一): 创建第一个WebRole程序与部署 Windows Azure入门教学系列 (二): 创建第一个 ...

  2. SQL Server 2008空间数据应用系列八:基于Bing Maps(Silverlight)的空间数据存储

    原文:SQL Server 2008空间数据应用系列八:基于Bing Maps(Silverlight)的空间数据存储 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft S ...

  3. java多线程系列(八)---CountDownLatch和CyclicBarrie

    CountDownLatch 前言:如有不正确的地方,还望指正. 目录 认识cpu.核心与线程 java多线程系列(一)之java多线程技能 java多线程系列(二)之对象变量的并发访问 java多线 ...

  4. C语言高速入门系列(八)

    C语言高速入门系列(八) C语言位运算与文件 本章引言: 在不知不觉中我们的C高速入门系列已经慢慢地接近尾声了,而在这一节中,我们会对 C语言中的位运算和文件进行解析,相信这两章对于一些人来说是陌生的 ...

  5. struts2官方 中文教程 系列八:异常处理

    在本教程中,我们将探讨如何启用Struts 2框架处理web应用程序生成的任何未捕获的异常.Struts 2提供了健壮的异常处理,包括能够自动记录任何未捕获的异常,并将用户重定向到错误web页面. 贴 ...

  6. C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理

    C#编译器优化那点事   使用C#编写程序,给最终用户的程序,是需要使用release配置的,而release配置和debug配置,有一个关键区别,就是release的编译器优化默认是启用的.优化代码 ...

  7. Bing Maps进阶系列八:在Bing Maps中集成OpenStreetMap地图

    Bing Maps进阶系列八:在Bing Maps中集成OpenStreetMap地图 OSM(OpenStreetMap-开放街道地图)服务就是一种发布自己地图数据图片为服务的一种实现类型,开放街道 ...

  8. 爬虫系列(八) 用requests实现天气查询

    这篇文章我们将使用 requests 调用天气查询接口,实现一个天气查询的小模块,下面先贴上最终的效果图 1.接口分析 虽然现在网络上有很多免费的天气查询接口,但是有很多网站都是需要注册登陆的,过程比 ...

  9. 在 Apache 上使用网络安全服务(NSS)实现 HTTPS--RHCE 系列(八)

        在 Apache 上使用网络安全服务(NSS)实现 HTTPS--RHCE 系列(八) 发布:linux培训 来源:Linux认证 时间:2015-12-21 15:26 分享到: 达内lin ...

  10. Keil MDK STM32系列(八) STM32F4基于HAL的PWM和定时器输出音频

    Keil MDK STM32系列 Keil MDK STM32系列(一) 基于标准外设库SPL的STM32F103开发 Keil MDK STM32系列(二) 基于标准外设库SPL的STM32F401 ...

随机推荐

  1. ceph for openstack快速部署实施

    for el6 即centos6 1,添加ceph 官方yum源 [root@ruiy ~]# cat /etc/yum.repos.d/ceph.repo[ceph-noarch]name=Ceph ...

  2. html中给图片添加热点

    <img src="images/index/top1.jpg" width="248" height="512" usemap=&q ...

  3. C#中log4net使用方法(一)

    Log4net是一个第三方开源组件,它设计的主要目的是组合,生成日志信息,同时将配置保存到各种存储介质或者展现平台中,在实际项目中,Log4net可以保存系统运行情况,可以在系统出现异常时,根据保存的 ...

  4. 温故而知新之数据库的分离和附加…高手请跳过….

    sql server2005分离数据库后,把路径下的两个文件拷到自己想要存放的目录下,然后再附加

  5. jQuery和DOM对象之间的转换

    jquery选择器得到的jquery对象和标准的 javascript中的document.getElementById()取得的dom对象是两种不同的对象类型,一般情况下,如S(’#id’)得到的是 ...

  6. mysql--自动增长

    create table teacher( t_id int primary key auto_increment, #auto_increment 自动增长 需要整型,还需要索引 t_name va ...

  7. Java 7源码分析第13篇 - 字节输入输出流(1)

    上一篇介绍了关于字节输入输出流的Java类框架,同时也简单介绍了一下各个类的作用,下面就来具体看一下这些类是怎么实现这些功能的. 1.InputStream和OutputStream InputStr ...

  8. javascirpt语法

    1.区分大小写 ECMAScript中的一切(变量.函数名和操作符)都区分大小写,而函数名不能使用typeof,因为它是一个关键字,但typeof则完全可以是一个有效的函数名. 2.标识符 指变量.函 ...

  9. 精读《javascript高级程序设计》笔记一——基本概念

    语法 严格模式 启用严格模式,在脚本顶部或函数内部上方添加"use strict";语句. 数据类型 typeof typeof返回undifined,boolean,number ...

  10. attempting to bokeyaunrun eclipse useing the jre instead of jdk,to run eclipse using

    关于eclipse运行出现,attempting to bokeyaunrun eclipse useing the jre instead of jdk,to run eclipse using错误 ...