html table space,HTML Tables

table {

font-family: arial, sans-serif;

border-collapse: collapse;

width: 100%;

}

td, th {

border: 1px solid #dddddd;

text-align: left;

padding: 8px;

}

tr:nth-child(even) {

background-color: #dddddd;

}

HTML Table

CompanyContactCountry
Alfreds FutterkisteMaria AndersGermany
Centro comercial MoctezumaFrancisco ChangMexico
Ernst HandelRoland MendelAustria
Island TradingHelen BennettUK
Laughing Bacchus WinecellarsYoshi TannamuriCanada
Magazzini Alimentari RiunitiGiovanni RovelliItaly

Defining an HTML Table

An HTML table is defined with the

Each table row is defined with the

tag. A table header is defined with the tag. By default, table headings are bold and centered. A table data/cell is defined with the tag.

HTML table

table row

table header

table data/cell

Note: The

elements are the data containers of the table.

They can contain all sorts of HTML elements; text, images, lists, other tables, etc.

HTML Table - Adding a Border

If you do not specify a border for the table, it will be displayed without borders.

A border is set using the CSS border property:

table, th, td {

border: 1px solid black;

}

Remember to define borders for both the table and the table cells.

HTML Table - Collapsed Borders 设置表格的边框是否被合并为一个单一的边框,还是象在标准的 HTML 中那样分开显示对应的脚本特性(即由原来的双框线变成单框线)

table, th, td {

border: 1px solid black;

border-collapse: collapse;

}

HTML Table - Adding Cell Padding 限定内容与边框的距离

Cell padding specifies the space between the cell content and its borders.

If you do not specify a padding, the table cells will be displayed without padding.

To set the padding, use the CSS padding property:

th, td {

padding: 15px;

}

HTML Table - Left-align Headings

By default, table headings are bold and centered.

To left-align the table headings, use the CSS text-align property:

th { text-align: left; }

[Try it Yourself »](https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_headings_left)

HTML Table - Adding Border Spacing

Border spacing specifies the space between the cells.

To set the border spacing for a table, use the CSS border-spacing property:

table {

border-spacing: 5px;

}

Note: If the table has collapsed borders, border-spacing has no effect.

HTML Table - Cells that Span Many Columns

To make a cell span more than one column, use the colspan attribute:

NameTelephone
Bill Gates5557785455577855

HTML Table - Cells that Span Many Rows

To make a cell span more than one row, use the rowspan attribute:

Name:Bill Gates
Telephone:55577854
55577855

HTML Table - Adding a Caption

To add a caption to a table, use the

tag:
Monthly savings
MonthSavings
January$100
February$50

Note: The

tag must be inserted immediately after the

A Special Style for One Table 定义表格的背景色和填充色等

To define a special style for a special table, add an id attribute to the table:

FirstnameLastnameAge
EveJackson94

Now you can define a special style for this table:

table#t01 {

width: 100%;

background-color: #f1f1c1;

}

table, th, td {

border: 1px solid black;

border-collapse: collapse;

}

th, td {

padding: 15px;

text-align: left;

}

table#t01 {

width: 100%;

background-color: #f1f1c1;

}

Styling Tables

FirstnameLastnameAge
JillSmith50
EveJackson94
JohnDoe80
FirstnameLastnameAge
JillSmith50
EveJackson94
JohnDoe80

And add more styles:

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 {

width:100%;

}

table, th, td {

border: 1px solid black;

border-collapse: collapse;

}

th, td {

padding: 15px;

text-align: left;

}

table#t01 tr:nth-child(even) {

background-color: #eee;

}

table#t01 tr:nth-child(odd) {

background-color: #fff;

}

table#t01 th {

background-color: black;

color: white;

}

Styling Tables

FirstnameLastnameAge
JillSmith50
EveJackson94
JohnDoe80
FirstnameLastnameAge
JillSmith50
EveJackson94
JohnDoe80

Chapter Summary

Use the HTML

Use the HTML

element to define a table row

Use the HTML

element to define a table data

Use the HTML

element to define a table heading

Use the HTML

element to define a table caption

Use the CSS border property to define a border

Use the CSS border-collapse property to collapse cell borders

Use the CSS padding property to add padding to cells

Use the CSS text-align property to align cell text

Use the CSS border-spacing property to set the spacing between cells

Use the colspan attribute to make a cell span many columns

Use the rowspan attribute to make a cell span many rows

Use the id attribute to uniquely define one table

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值