
使用 CSS 可以使 HTML 表格更美觀。CompanyContactCountryAlfreds FutterkisteMaria AndersGermanyBerglunds snabbk?pChristina BerglundSwedenCentro comercial MoctezumaFrancisco ChangMexicoErnst HandelRoland MendelAustriaIsland TradingHelen BennettUKK?niglich EssenPhilip CramerGermanyLaughing Bacchus WinecellarsYoshi TannamuriCanadaMagazzini Alimentari RiunitiGiovanni RovelliItalyNorth/SouthSimon CrowtherUKParis spécialitésMarie BertrandFranceThe Big CheeseLiz NixonUSAVaffeljernetPalle IbsenDenmark表格邊框指定CSS表格邊框使用border屬性。下面的例子指定了一個表格的Th和TD元素的黑色邊框?qū)嵗齮able, th, td { border: 1px solid black; }請注意在上面的例子中的表格有雙邊框。這是因為表和th/ td元素有獨立的邊界。為了顯示一個表的單個邊框使用 border-collapse屬性。折疊邊框border-collapse 屬性設置表格的邊框是否被折疊成一個單一的邊框或隔開實例table { border-collapse:collapse; } table,th, td { border: 1px solid black; }表格寬度和高度Width和height屬性定義表格的寬度和高度。下面的例子是設置100的寬度50像素的th元素的高度的表格實例table { width:100%; } th { height:50px; }表格文字對齊表格中的文本對齊和垂直對齊屬性。text-align屬性設置水平對齊方式向左右或中心實例td { text-align:right; }垂直對齊屬性設置垂直對齊比如頂部底部或中間實例td { height:50px; vertical-align:bottom; }表格填充如需控制邊框和表格內(nèi)容之間的間距應使用td和th元素的填充屬性實例td { padding:15px; }表格顏色下面的例子指定邊框的顏色和th元素的文本和背景顏色實例table, td, th { border:1px solid green; } th { background-color:green; color:white; }