css格式化一个表格之border-collapse: collapse的使用

我们要完成的表格如下图所示。完成这个任务有许多方法,但是我建议你使用和向导中所用的相似的模式来完成以下的事情。

  • 把标题和包含数字的列数据右对齐
  • 把标题和包含文本的列数据左对齐
  • 添加顶部和底部边框,以及页脚上方的边框
  • 将主表的所有奇数行条纹化

css

table {
    border-collapse: collapse;

    font-size: 75%;
  }
thead th:nth-child(2),
thead th:nth-child(3),
tbody td:nth-child(2),
tbody td:nth-child(3),
tfoot :first-child{
text-align:right;
}
thead th:nth-child(1),
thead th:nth-child(4),
tbody td:nth-child(1),
tbody td:nth-child(4),
tfoot :last-child{
text-align:left;
}

thead {
border-top: solid 1px #c0c0c0;
}
tfoot {
border-bottom:solid 1px #c0c0c0;
border-top: solid 1px #c0c0c0;

}
tbody tr:nth-child(odd) {
background-color: #c0c0c0;
}

注意!!! 

border-collapse: collapse;是关键,不添加thead和tfoot中的boder属性不生效.

 html

 <table>
  <caption>A summary of the UK's most famous punk bands</caption>
  <thead>
    <tr>
      <th scope="col">Band</th>
      <th scope="col">Year formed</th>
      <th scope="col">No. of Albums</th>
      <th scope="col">Most famous song</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Buzzcocks</th>
      <td>1976</td>
      <td>9</td>
      <td>Ever fallen in love (with someone you shouldn't've)</td>
    </tr>
    <tr>
      <th scope="row">The Clash</th>
      <td>1976</td>
      <td>6</td>
      <td>London Calling</td>
    </tr>
    <tr>
      <th scope="row">The Damned</th>
      <td>1976</td>
      <td>10</td>
      <td>Smash it up</td>
    </tr>
    <tr>
      <th scope="row">Sex Pistols</th>
      <td>1975</td>
      <td>1</td>
      <td>Anarchy in the UK</td>
    </tr>
    <tr>
      <th scope="row">Sham 69</th>
      <td>1976</td>
      <td>13</td>
      <td>If the kids are united</td>
    </tr>
    <tr>
      <th scope="row">Siouxsie and the Banshees</th>
      <td>1976</td>
      <td>11</td>
      <td>Hong Kong Garden</td>
    </tr>
    <tr>
      <th scope="row">Stiff Little Fingers</th>
      <td>1977</td>
      <td>10</td>
      <td>Suspect Device</td>
    </tr>
    <tr>
      <th scope="row">The Stranglers</th>
      <td>1974</td>
      <td>17</td>
      <td>No More Heroes</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th scope="row" colspan="2">Total albums</th>
      <td colspan="2">77</td>
    </tr>
  </tfoot>
</table>

文档链接 https://developer.mozilla.org/zh-CN/docs/Learn/CSS/Building_blocks/Advanced_styling_effects

<html> <head> <title>理财网址导航『个人理财网址导航』</title> <meta name="keywords" content="理财网址导航,个人理财网址导航" /> <meta name="description" content="个人理财网址导航是提倡安全、健康的免费导航站,最适淘宝、拍拍、有啊网店实用 网址 !个人理财网址导航商家的首选实用网址,做最专业的方便您我,精选网址导航,让生活充满方便哈" /> <meta name="GENERATOR" content="Microsoft FrontPage 6.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta content="text/html; charset=gb2312" http-equiv="Content-Type"/> <style type="text/css"> <!-- td, body { font-family: "宋体"; font-size: 14px } a:link{ color:#000000; text-decoration:none} a:visited{COLOR: #000000; TEXT-DECORATION: none} .STYLE4 { color: #00FF00; } a:active{color:green;text-decoration:none} a:hover{ color: #009933; text-decoration: underline } body,td,th { font-size: 15px; } sd:link { font-size: 15px; font-style: normal; font-weight: bold; color: #7BD773; } .STYLE1 {font-size: 16px} .STYLE3 { font-size: 16px; color: #00FF00; } .h1 a:link {font-size:14px;color: #0000FF;} --> </style> <script> function setTab(s,n){ for(i=1;i<=4;i++){ document.getElementById("tab"+i).style.display="none"; } document.getElementById("tab"+s).style.display = "block"; } </script> <base target="_blank"> </head> <script language="javascript"> <!-- function clearpass(){ document.loginmail.pass.value=""; } //--> </script> <body bgcolor="#E7FADE" leftmargin="0" marginwidth="0" marginheight="0" topmargin="2"> <div align="center"> <table width="100%" height="0" border="0" align="center" > <td align="center"> </td> </table> <center> <table width=990 height=70 style="border-collapse: collapse" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0" border="1"> <tr> <td height=70 width=155> <p align=center></td> <td height=40 width=205> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: 1px solid #7BD676; " width="140" height="60"> <tr> <td height=65> </td> </tr> </table></td> <td height=60 width=257> <table border="1" cellpadding="0" cellspac
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值