2013-04-23 58 views
-1
<table border="1" style="background-color:yellow;border:1px dotted black;width:80%;border-collapse:collapse;"> 
<tr style="background-color:orange;color:white;"> 
<th style="padding:3px;">Table header</th><th style="padding:3px;">Table header</th> 
</tr> 
<tr> 
<td style="padding:3px;">Table cell 1</td><td style="padding:3px;">Table cell 2</td> 
</tr> 
<tr> 
<td style="padding:3px;">Table cell 3</td><td style="padding:3px;">Table cell 4</td> 
</tr> 
</table> 

我的問題是,如何將此html示例中的內聯CSS轉換爲外部樣式表?將某些內聯CSS轉換爲單獨的表格

css會是這樣嗎?

tr {background-color:orange;color:white;} 
table {background-color:yellow;border:1px dotted black;width:80%;border-collapse:collapse;} 
td, th {padding:3px;} 
+1

應該正常工作...請務必在標題中引用新的外部表。 – tymeJV 2013-04-23 21:02:32

+0

你試過比較之前/之後嗎?如果他們不同,有什麼不同? – cimmanon 2013-04-23 21:15:43

回答

0

使用table tr:first-child而不是tr因爲只有第一行有內嵌樣式:

table { 
background-color: yellow; 
border: 1px dotted black; 
border-collapse: collapse; 
width: 80%; 
} 

table th, table td { 
padding: 3px; 
} 

table tr:first-child { 
background-color: orange; 
color: white; 
} 

http://jsfiddle.net/URBMh/2/

+0

'tr:first-child'也可以工作嗎? – 2013-04-23 21:06:35

+0

是的,它會起作用,因爲''first-child''因爲它在傳統瀏覽器(讀取IE)中不被完全支持,所以''是'

'的孩子。 – Adrift2013-04-23 21:11:25

+1

。您應該考慮通過添加一個'

'和''元素 – Pevara2013-04-23 21:13:58