CSS Tables

CSS Tables

The look of an HTML table can be greatly improved with CSS:

CompanyContactCountry
Alfreds FutterkisteMaria AndersGermany
Berglunds snabbköpChristina BerglundSweden
Centro comercial MoctezumaFrancisco ChangMexico
Ernst HandelRoland MendelAustria
Island TradingHelen BennettUK
Königlich EssenPhilip CramerGermany
Laughing Bacchus WinecellarsYoshi TannamuriCanada
Magazzini Alimentari RiunitiGiovanni RovelliItaly
North/SouthSimon CrowtherUK
Paris spécialitésMarie BertrandFrance
The Big CheeseLiz NixonUSA
VaffeljernetPalle IbsenDenmark

Table Borders

To specify table borders in CSS, use the border property.

The example below specifies a black border for table, th, and td elements:

Example

table, th, td
{
border: 1px solid black;
}

Try it yourself »

Notice that the table in the example above has double borders. This is because both the table, th, and td elements have separate borders.

To display a single border for the table, use the border-collapse property.

Collapse Borders

The border-collapse property sets whether the table borders are collapsed into a single border or separated:

Example

table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid black;
}

Try it yourself »


Table Width and Height

Width and height of a table is defined by the width and height properties.

The example below sets the width of the table to 100%, and the height of the th elements to 50px:

Example

table 
{
width:100%;
}
th
{
height:50px;
}

Try it yourself »


Table Text Alignment

The text in a table is aligned with the text-align and vertical-align properties.

The text-align property sets the horizontal alignment, like left, right, or center:

Example

td
{
text-align:right;
}

Try it yourself »

The vertical-align property sets the vertical alignment, like top, bottom, or middle:

Example

td
{
height:50px;
vertical-align:bottom;
}

Try it yourself »


Table Padding

To control the space between the border and content in a table, use the padding property on td and th elements:

Example

td
{
padding:15px;
}

Try it yourself »


Table Color

The example below specifies the color of the borders, and the text and background color of th elements:

Example

table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}

Try it yourself »

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值