关于HTML表格的table和div

本文探讨了HTML中table表格和div的区别。Table用于创建表格,包括标题、表头、主体和表尾,而div作为分块元素,常用于布局。文章还详细解释了块级标签与行内标签的不同特性,如块级标签占满一行,行内标签在同一行显示,以及它们在设置尺寸和边距方面的差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Table和div

Table 表格
在这里插入图片描述这是一个4行4列的表格。第一行是表头,其余三行是主体。

表格的组成部分标题 表头 主体 表尾

<table>定义一个表格
<caption> 定义表格的标题
<thead> 定义表头的部分
<tbody> 定义个主体(数据)部分
<tfoot> 定义表尾,一般来显示汇总信息

<tr> 定义一行
<th> <td> 来定义数据项(单元格)
          <th>一般用于表头,有加粗的样式
          <td>一般用于主体,没有加粗的样式
<td rowspan> <td colspan>分别定义了单元格的跨行的行数,跨列的列数。
cellpadding:数据与表格之间的距离
cellspacing:表格与表格之间的距离

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>阶段项目</title>
</head>
<body>
<form>
<table border="1" cellspacing="0" cellpadding="10" align="center" width="1000px">
    <caption><h2>新员工入职登记表</h2></caption>
    <thead>
    <tr>
        <th>姓名</th>
        <td></td>
        <th>性别</th>
        <td>
            <input type="radio" name="sex"><input type="radio" name="sex"><br>
        </td>
        <th>出生日期</th>
        <td></td>
        <td rowspan="5" align="center"><input type="file" ></td>
    </tr>
    <tr>
        <th>曾用名</th>
        <td></td>
        <th>体重</th>
        <td></td>
        <th>身高</th>
        <td></td>
    </tr>
    <tr>
        <th>民族</th>
        <td align="center">
            <select>
                <option></option>
                <option></option>
                <option></option>
            </select>
        </td>
        <th>籍贯</th>
        <td></td>
        <th>婚姻状况</th>
        <td><input type="radio" name="marriage">已婚
            <input type="radio" name="marriage">未婚<br></td>
    </tr><tr>
        <th>政治面貌</th>
        <td><input type="radio" name="political">党员
            <input type="radio" name="political">团员</td>
        <th>健康状况</th>
        <td></td>
        <th>血型</th>
        <td>
            <input type="radio" name="a">A
            <input type="radio" name="b">B
            <input type="radio" name="ab">AB
        </td>
    </tr>
    <tr>
        <th>身份证号码</th>
        <td colspan="5"></td>
    </tr>
    </thead>
</table>
</form>
</body>
</html>

在这里插入图片描述

div

定义一个分块(division)
特点:在新的一行显示 块级标签

块级标签 与 行内标签 的区别

块级标签占满行 行内标签会按照顺序从左到右依次排列

块级标签:h1-h6 p ol ul li div table dl form
行内标签:span a br lable I em
行内块标签:img input

块级元素的特点:display:block
1.每个块都是从新的一行开始,后面的元素会另起一行
2.元素的宽度,高度,行高,内外边距都可以设置的
3.如果不设置元素的宽度,是它父容器的100%,除非你给他设定高度

行内元素的特点:display:inline
1.和其他的元素都在一行上
2.不能设置元素的宽度,高度,行高,内外边距
3.元素的宽度是它包含文字或图片的宽度,不能改变

行内块元素的特点:display:inline-block
1.和其他的元素都在一行上
2.宽度,高度,行高,内外边距都可以设置的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值