html <table>,HTML <table> 标签

# HTML <table> 标签

## 实例

一个简单的 HTML 表格,包含两行两列:

```

MonthSavings
January$100

```

## 浏览器支持

| IE | Firefox | Chrome | Safari | Opera |

| --- | --- | --- | --- | --- |

所有浏览器都支持 <table> 标签。

## 定义和用法

<table> 标签定义 HTML 表格。

简单的 HTML 表格由 table 元素以及一个或多个 tr、th 或 td 元素组成。

tr 元素定义表格行,th 元素定义表头,td 元素定义表格单元。

更复杂的 HTML 表格也可能包括 caption、col、colgroup、thead、tfoot 以及 tbody 元素。

## HTML 与 XHTML 之间的差异

在 HTML 4.01 中,table 元素的 "align" 和 "bgcolor" 属性是不被赞成使用的。

在 XHTML 1.0 Strict DTD,table 元素的 "align" 和 "bgcolor" 属性是不被支持的。

## 可选的属性

| 属性 | 值 | 描述 |

| --- | --- | --- |

| [align](/tags/att_table_align.asp "HTML <table> 标签的 align 属性") | `left` `center` `right` | 不赞成使用。请使用样式代替。规定表格相对周围元素的对齐方式。 |

| [bgcolor](/tags/att_table_bgcolor.asp "HTML <table> 标签的 bgcolor 属性") | _rgb(x,x,x)_ _#xxxxxx_ _colorname_ |不赞成使用。请使用样式代替。规定表格的背景颜色。 |

| [border](/tags/att_table_border.asp "HTML <table> 标签的 border 属性") | _pixels_ | 规定表格边框的宽度。 |

| [cellpadding](/tags/att_table_cellpadding.asp "HTML <table> 标签的 cellpadding 属性") | _pixels_ _%_ | 规定单元边沿与其内容之间的空白。 |

| [cellspacing](/tags/att_table_cellspacing.asp "HTML <table> 标签的 cellspacing 属性") | _pixels_ _%_ | 规定单元格之间的空白。 |

| [frame](/tags/att_table_frame.asp "HTML <table> 标签的 frame 属性") | `void` `above` `below` `hsides` `lhs` `rhs` `vsides` `box` `border` | 规定外侧边框的哪个部分是可见的。 |

| [rules](/tags/att_table_rules.asp "HTML <table> 标签的 rules 属性") | `none` `groups` `rows` `cols` `all` | 规定内侧边框的哪个部分是可见的。 |

| [summary](/tags/att_table_summary.asp "HTML <table> 标签的 summary 属性") | _text_ | 规定表格的摘要。 |

| [width](/tags/att_table_width.asp "HTML <table> 标签的 width 属性") | _%_ _pixels_ | 规定表格的宽度。 |

## 全局属性

<table> 标签支持 [HTML 中的全局属性](/tags/html_ref_standardattributes.asp)。

## 事件属性

<table> 标签支持 [HTML 中的事件属性](/tags/html_ref_eventattributes.asp)。

## TIY 实例

[表格](/tiy/t.asp?f=html_tables)

这个例子演示如何在 HTML 文档中创建表格。

```

每个表格由 table 标签开始。

每个表格行由 tr 标签开始。

每个表格数据由 td 标签开始。

一列:
100
一行三列:
100200300
两行三列:
100200300
400500600

```

[表格边框](/tiy/t.asp?f=html_table_borders)

本例演示各种类型的表格边框。

```

带有普通的边框:
FirstRow
SecondRow
带有粗的边框:
FirstRow
SecondRow
带有很粗的边框:
FirstRow
SecondRow

```

[没有边框的表格](/tiy/t.asp?f=html_tables2)

本例演示一个没有边框的表格。

```

这个表格没有边框:
100200300
400500600
这个表格也没有边框:
100200300
400500600

```

[表格中的标题(Headings)](/tiy/t.asp?f=html_table_headers)

本例演示如何显示表格标题。

```

表头:
姓名电话电话
Bill Gates555 77 854555 77 855
垂直的表头:
姓名Bill Gates
电话555 77 854
电话555 77 855

```

[空单元格](/tiy/t.asp?f=html_table_nbsp)

本例展示如何使用 " " 处理没有内容的单元格。

```

Some textSome text
Some text

正如您看到的,其中一个单元没有边框。这是因为它是空的。在该单元中插入一个空格后,仍然没有边框。

我们的技巧是在单元中插入一个 no-breaking 空格。

no-breaking 空格是一个字符实体。如果您不清楚什么是字符实体,请阅读关于字符实体的章节。

no-breaking 空格由和号开始 ("&"),然后是字符"nbsp",并以分号结尾(";")。

```

[带有标题的表格](/tiy/t.asp?f=html_tables3)

本例演示一个带标题 (caption) 的表格

```

这个表格有一个标题,以及粗边框:
我的标题
100200300
400500600

```

[跨行或跨列的表格单元格](/tiy/t.asp?f=html_table_span)

本例演示如何定义跨行或跨列的表格单元格。

```

横跨两列的单元格:
姓名电话
Bill Gates555 77 854555 77 855
横跨两行的单元格:
姓名Bill Gates
电话555 77 854
555 77 855

```

[表格内的标签](/tiy/t.asp?f=html_table_elements)

本例演示如何在不同的元素内显示元素。

```

这是一个段落。

这是另一个段落。

这个单元包含一个表格:
AB
CD
这个单元包含一个列表:
  • 苹果
  • 香蕉
  • 菠萝
HELLO

```

[单元格填充(Cell padding)](/tiy/t.asp?f=html_table_cellpadding)

本例演示如何使用单元格填充来创建单元格内容与其边框之间的空白。

```

没有 cellpadding:
FirstRow
SecondRow
带有 cellpadding:

cellpadding="10">

FirstRowSecondRow

```

[单元格间距(Cell spacing)](/tiy/t.asp?f=html_table_cellspacing)

本例演示如何使用单元格间距增加单元格之间的距离。

```

没有 cellspacing:
FirstRow
SecondRow
带有 cellspacing:

cellspacing="10">

FirstRowSecondRow

```

[向表格添加背景颜色或背景图像](/tiy/t.asp?f=html_table_background)

本例演示如何向表格添加背景

```

背景颜色:

bgcolor="red">

FirstRowSecondRow
背景图像:

background="/i/eg_bg_07.gif">

FirstRowSecondRow

```

[向表格单元添加背景颜色或者背景图像](/tiy/t.asp?f=html_table_cellbackground)

本例演示如何向一个或者更多表格单元添加背景

```

#### 单元背景:

First |

Row |

Second |

Row |

```

[在表格单元中排列内容](/tiy/t.asp?f=html_table_align)

本例演示如何使用 "align" 属性排列单元格内容,以便创建一个美观的表格。

```

消费项目....一月二月
衣服$241.10$50.20
化妆品$30.00$44.45
食物$730.40$650.00
总计$1001.50$744.65

```

[框架(frame)属性](/tiy/t.asp?f=html_table_frame)

本例演示如何使用 "frame" 属性来控制围绕表格的边框。

```

注释:frame 属性无法在 Internet Explorer 中正确地显示。

Table with frame="box":

MonthSavings
January$100

Table with frame="above":

MonthSavings
January$100

Table with frame="below":

MonthSavings
January$100

Table with frame="hsides":

MonthSavings
January$100

Table with frame="vsides":

MonthSavings
January$100

```

## 相关页面

HTML DOM 参考手册:[Table 对象](/jsref/dom_obj_table.asp "HTML DOM Table 对象")

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值