2008-12-12 38 views
10

VStudio ASP.NET提供了以下消息:HTML屬性bgcolor已棄用:請改用什麼?

Attribute 'bgcolor' is considered outdated. A newer construct is recommended. 

什麼是推薦的結構?

bgcolor<td>元素內。
另一個相關的消息是:

Attribute 'bordercolor' is not a valid attribute of element 'table'. 

有誰知道我可能會發現新的替代品?

+7

即使ASP開始thinki,你知道它是壞的你的HTML已被棄用...;) – jalf 2008-12-12 06:28:59

回答

19

BGColor在W3C HTML 4.0規範已被否決。

較新的Web站點和Web應用程序使用CSS(層疊樣式表)來渲染同樣的事情,具體如下:

body { 
    background-color : #ffffff; 
} 

對於表,請執行以下操作:

<table> 

<tr id="row1"> 
    <th>Header 1</th>  <td>Cell 1</td>  <td>Cell 2</td> 
</tr> 
<tr id="row2"> 
    <th>Header 2</th>  <td>Cell 3</td>  <td>Cell 4</td> 
</tr> 
<tr id="row3"> 
    <th>Header 3</th>  <td>Cell 5</td>  <td>Cell 6</td> 
</tr> 
</table> 

而在你的CSS:

th { text-align: center; font-weight: bold; vertical-align: baseline } 

td { vertical-align: middle } 

table { border-collapse: collapse; background-color: #ffffff } 
tr#row1 { border-top: 3px solid blue } 
tr#row2 { border-top: 1px solid black } 
tr#row3 { border-top: 1px solid black } 

這將使它如此表中將有一個背景顏色,並做不同t填充表格數據/表格行的其餘部分。

簡單地說,在你的樣式表,並引用它在網頁上像這樣:

<link rel="stylesheet" href="style.css" TYPE="text/css" media="screen"> 

你可以把幾乎任何你在你的CSS一樣,對CSS herehere更多信息。

2

較新的替代品是級聯樣式表(CSS)。任何控制HTML文檔可視外觀的屬性或元素都將被棄用。應該使用CSS指定視覺樣式。

4

最好的猜測是CSS的background-colorborder-color

<table style="border-color: #ffffff;"> 

<td style="background-color: #000000;"> 
+0

謝謝喬納森。這完全回答了我的直接問題。儘管如此,CSS的路徑是我應該長期下去的。 – 2008-12-12 02:05:33

+1

是的,一旦你做到了,它會讓你的生活更輕鬆。 – 2008-12-12 19:11:39

2

推薦的做法是使用CSS。你可以爲你的表設置CSS類。事情是這樣的:

CSS:

.MyTable { 
    border: solid 2px #000; 
} 

.MySpecialCell { 
    background-color: #F00; 
} 

HTML:

<table class="MyTable"> 
    <tr> 
     <td class="MySpecialCell">...</td> 
    </tr> 
</table> 
2

另外值得一提的是,儘管不是優雅作爲一個單獨的風格部分,它是有效的,現在做這個內聯樣式,如果這是你更舒適的:

<body style="background-color: #ccc;">