2013-04-23 56 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