web前端开发零基础入门6(关于HTML表格)


这两天浅学了一下表格,下面来小小总结一下

一.表格的定义

table 标签定义 HTML 表格。简单的 HTML 表格由 table 元素以及一个或多个 tr、th或 td元素组成表格结构;其中: tr>元素定义表格行,th 元素定义表头,td 元素定义表格单元。
为了让表格更美观,我们会用到:border,colspan,rowspan,align,bgcolor 等来美化表格。

二.表格的标签

之前我们说过在VS里面使用的标签,比如什么meta标签啊。
在下面这个链接里面有我详细说明的:

http://t.csdn.cn/XGKeQ

三.单元格边框(border)

表格边框:在使用table border=“1” /table 的方式来定义,其中:数字表示边框的宽度,单位为像素,下面有一个我写的例子:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>
<body>
    <table border="1" cellspacing="0" align="center">
        <caption><font size="20" color="pink" ><h3 align="center">成绩单</h3></font></caption>
        <tr>
            <th width="100" height="40" bgcolor="aqua" align="center">学号</th>
            <th width="100" height="40" bgcolor="aqua" align="center">姓名</th>
            
            <th width="100" height="20" bgcolor="pink" align="center" conspan="3" >平时成绩 </th>
            
            <th width="100" height="40" bgcolor="aqua" align="center">期末成绩</th>
            
            <th width="100" height="40" bgcolor="aqua" align="center">总成绩</th>
        
        </tr>
        <th width="100" height="40" bgcolor="aqua" align="center">001</th>
        <th width="100" height="40" bgcolor="aqua" align="center">ZZZ</th>
        <th width="100" height="40" bgcolor="aqua" align="center">90</th>
        <th width="100" height="40" bgcolor="aqua" align="center">90</th>
        <th width="100" height="40" bgcolor="aqua" align="center">180</th>
        
        <tr>

        </tr>
    </tr>
    <th width="100" height="40" bgcolor="aqua" align="center">002</th>
    <th width="100" height="40" bgcolor="aqua" align="center">LLL</th>
    <th width="100" height="40" bgcolor="aqua" align="center">80</th>
    <th width="100" height="40" bgcolor="aqua" align="center">100</th>
    <th width="100" height="40" bgcolor="aqua" align="center">180</th>
    <tr>
        

    </tr>
    <th width="100" height="40" bgcolor="aqua" align="center">003</th>
    <th width="100" height="40" bgcolor="aqua" align="center">WWW</th>
    <th width="100" height="40" bgcolor="aqua" align="center">100</th>
    <th width="100" height="40" bgcolor="aqua" align="center">90</th>
    <th width="100" height="40" bgcolor="aqua" align="center">190</th>
    <tr>

    
    </table>
    
</body>
</html>

在这里插入图片描述

四.合并单元格

1.合并行单元格(colspan)

合并单元格时,合并行使用:colspan=“2”; 合并列使用:rowspan=“2” (这里的 ‘2’ 表明合并两个单元格),举例如下:

<html>
<head>
<meta charset="utf-8">
<title>HTML表格合并单元格--张力文</title>
</head>
<body>

<h4>合并行单元格:</h4>
<table border="1">
<caption>通讯录</caption>
<tr>
  <th>姓名</th>
  <th colspan="2">邮箱</th>
</tr>
<tr>
  <td>张力文</td>
  <td>123456@qq.com</td>
  <td>123456@163.com</td>
</tr>
</table>

</body>
</html>

在这里插入代码片

在这里插入图片描述

2.合并列单元格(rowspan)

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML表格合并单元格--张力文</title>
</head>
<body>

<h4>合并列单元格:</h4>
<table border="1">
<tr>
  <th>姓名</th>
  <td>张力文</td>
</tr>
<tr>
  <th rowspan="3">邮箱</th>
  <td>123456@qq.com</td>
</tr>
<tr>
  <td>123456@163.com</td>
</tr>
<tr>
  <td>123456@sina.com</td>
</tr>
</table>

</body>
</html>

在这里插入图片描述

五.表格格式设置

在这里插入图片描述

<table width="600" border="2">
    <tr align="center">
        <th> 编号 </th>
        <th>姓名</th>
        <th>性别</th>
    </tr>
    <tr>
        <td align="center">1</td>
        <td align="left">张力文</td>
        <td align="right"></td>
    </tr>
    <tr align="right">
        <td>2</td>
        <td align="left">邹雪森</td>
        <td></td>
    </tr>
</table>

在这里插入图片描述

六.背景色&图片(bgcolor & background)

我们通常会直接使用meta标签,比如bgcolor=“aaa”。就会呈现我们想要的背景颜色。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>
<body>
    <table border="1" cellspacing="0" align="center">
        <caption><font size="20" color="pink" ><h3 align="center">成绩单</h3></font></caption>
        <tr>
            <th width="100" height="40" bgcolor="aqua" align="center">学号</th>
            <th width="100" height="40" bgcolor="aqua" align="center">姓名</th>
            
            <th width="100" height="20" bgcolor="pink" align="center" conspan="3" >平时成绩 </th>
            
            <th width="100" height="40" bgcolor="aqua" align="center">期末成绩</th>
            
            <th width="100" height="40" bgcolor="aqua" align="center">总成绩</th>
        
        </tr>
        <th width="100" height="40" bgcolor="aqua" align="center">001</th>
        <th width="100" height="40" bgcolor="aqua" align="center">ZZZ</th>
        <th width="100" height="40" bgcolor="aqua" align="center">90</th>
        <th width="100" height="40" bgcolor="aqua" align="center">90</th>
        <th width="100" height="40" bgcolor="aqua" align="center">180</th>
        
        <tr>

        </tr>
    </tr>
    <th width="100" height="40" bgcolor="aqua" align="center">002</th>
    <th width="100" height="40" bgcolor="aqua" align="center">LLL</th>
    <th width="100" height="40" bgcolor="aqua" align="center">80</th>
    <th width="100" height="40" bgcolor="aqua" align="center">100</th>
    <th width="100" height="40" bgcolor="aqua" align="center">180</th>
    <tr>
        

    </tr>
    <th width="100" height="40" bgcolor="aqua" align="center">003</th>
    <th width="100" height="40" bgcolor="aqua" align="center">WWW</th>
    <th width="100" height="40" bgcolor="aqua" align="center">100</th>
    <th width="100" height="40" bgcolor="aqua" align="center">90</th>
    <th width="100" height="40" bgcolor="aqua" align="center">190</th>
    <tr>

    
    </table>
    
</body>
</html>

在这里插入图片描述
比如这里的“平时成绩”就是粉色(pink)和其他模块的不一样。

表格背景色&图片

在表格的标签上增加bgcolor 或者 background,就可以添加背景色或者背景图片,以背景图片为例;

<table width="600" border="2" background='https://p1.ssl.qhimgs1.com/sdr/400__/t01f04c2504aa62bab7.gif'>
    <tr align="center">
        <th> 编号 </th>
        <th>姓名</th>
        <th>性别</th>
    </tr>
    <tr>
        <td align="center">1</td>
        <td align="left">马里奥</td>
        <td align="right"></td>
    </tr>
    <tr align="right">
        <td>2</td>
        <td align="left">桃花公主</td>
        <td></td>
    </tr>

</table>

在这里插入图片描述
在这里插入图片描述

七.单元格的边距(cellpadding)

在table标签使用cellpadding 即可,方法与上面的图片一样,直接举例如下:

<table width="600" border="2" cellspacing="8">
    <tr align="center">
        <th> 编号 </th>
        <th>姓名</th>
        <th>性别</th>
    </tr>
    <tr>
        <td align="center">1</td>
        <td align="left" bgcolor='red' >邹雪森</td>
        <td align="right"></td>
    </tr>
    <tr align="right">
        <td>2</td>
        <td align="left">张力文</td>
        <td></td>
    </tr>
</table>

在这里插入图片描述

八.显示部分边框(frame & rules)

|frame 键值 效果
void 不显示外侧边框
above 显示上部的外侧边框
below 显示下部的外侧边框
hsides 显示上部和下部的外侧边框
vsides 显示左边和右边的外侧边框
lhs 显示左边的外侧边框
rhs 显示右边的外侧边框
box 在所有四个边上显示外侧边框
border 在所有四个边上显示外侧边框

none 没有线条
groups 位于行组和列组之间的线条
rows 位于行之间的线条
cols 位于列之间的线条
all 位于行和列之间的线条

2022.7.8(改)

  • 3
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值