css定義table

來源:互聯網
上載者:User

div寫多了,偶爾遇到table現在還覺得麻煩,又是邊框,又是間距什麼的,覺得定義太多,看看我遇到的一個table

代碼如下:

<table cellspacing="0" cellpadding="8" width="100%" bordercolor="#C4E2FF" bordercolordark="#FFFFFF" bgcolor="#E8FBFF" border="1">
    <tr>
    <td align="right" width="17%">QQ號碼:</td>
    <td align="left" width="83%">123456</td>
    </tr>
    <tr>
    <td align="right">MSN:</td>
    <td align="left">123456@1222.com</td>
    </tr>
</table>

看看定義挺多的吧,還不相容,bordercolordark這個在firefox和opera就不行,表格在ie是細線有顏色,到了firefox,opera就變粗變黑,醜死。

試試用css來定義吧,找了一堆網站,被我搞定,代碼如下:

<style>
table{border-collapse:collapse;border:1px solid #C4E2FF;background:#E8FBFF;width:100%;}
td{padding:10px 5px;line-height:40px;border:1px solid #C4E2FF;}
</style>
<table>
    <tr>
    <td align="right" width="17%">QQ號碼:</td>
    <td align="left" width="83%">123456</td>
    </tr>
    <tr>
    <td align="right">MSN:</td>
    <td align="left">123456@1222.com</td>
    </tr>
</table>

注意border-collapse:collapse;是保證在firefox,opera下面細線的關鍵,並且td要加上border要不然裡面就沒有線了。

ok,ie/firefox/opera測試通過,把table解放出來真好:)

轉自:http://www.cnblogs.com/xiaoman_890/archive/2009/05/11/1454207.html

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.