2012-09-04 89 views
1

我找到了一個CSS教程來設置表格的樣式,但在我的頁面上還有其他表格。所以我無法弄清楚如何在這裏使用選擇器。 tr:nth-of-type(odd)是選擇器。但我希望這隻能用於名爲playerslist的表idclass類特定類型(單數)

<table id="playerslist"> 
    <thead> 
     <tr> 
      <th>Player Name</th> 
      <th>Player #</th> 
      <th>Team</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>Simon</td> 
      <td>25</td> 
      <td>Team A</td> 
     </tr> 
     <tr> 
      <td>Richard</td> 
      <td>5</td> 
      <td>Team B</td> 
     </tr> 
    </tbody> 
</table> 

任何想法如何定位與playerslistid表的tr:nth-of-type(odd)thtd元素?

謝謝

回答

6

指定表格的class和id在你的風格定義:

table#playerslist tr:nth-of-type(odd) { 
    // your styles 
} 
+0

謝謝你,好主意:) – cevizmx

+2

我不認爲這是想法,如果你發現了一分鐘,有點了解[CSS選擇器]這是很基本的:)( http://www.w3schools.com/cssref/css_selectors.asp)。 –

4

要與idclass稱爲playerslist,使用

table#playerslist tr:nth-of-type(odd), 
table.playerslist tr:nth-of-type(odd) 
{/* styling */} 
靶向 tabletr:nth-of-type(odd)元素

要定位th和有id='playerslist'一個table的元,使用

table#playerslist th, 
table#playerslist td {/* styling */} 
+0

感謝您舉例 – cevizmx

+0

+1,因爲您的答案比接受的答案要好。 – Chris