2013-04-08 30 views
2

我試圖在第三個打印的背景上使用:nth-​​child(5)展開圖像。但它沒有抓住它。難道我做錯了什麼?:nth-​​child()不工作

table#OppPracticeOverview tr th { 
    padding:5px !important; 
    background-color:transparent; 
} 
table#OppPracticeOverview tr th img { 
    width:47px; 
    height:22px; 
    float:left; 
    margin:-5px 0 0 -42px; 
    position:absolute; 
    z-index:-1; 
} 
table#OppPracticeOverview tr th img:nth-child(5) { 
    width:110px; 
    height:22px; 
    float:left; 
    margin:-5px 0 0 -105px; 
    position:absolute; 
    z-index:-1; 
} 

HTML:

<table id="OppPracticeOverview"> 
<tbody> 
    <tr> 
     <th> 
      Patients 
      <img src="/images/img-CCCCCC.png"> 
     </th> 
     <td> 
     <th> 
      On Hold 
      <img src="/images/img-CCCCCC.png"> 
     </th> 
     <td> 
     <th> 
      Reattribution Request 
      <img src="/images/img-CCCCCC.png"> 
     </th> 
     <td> 
    </tr> 
</tbody> 

+2

爲什麼你有一個td纏繞在一起,還沒有封閉?看看這裏的結局 - http://www.w3schools.com/tags/tag_th.asp,可能是問題的一部分。 – blackhawk 2013-04-08 14:18:09

+0

不正確的HTML語法和不正確的數字在nth-child中的組合是你的問題。 – Michael 2013-04-08 14:19:35

+0

@blachawk:其實我不認爲td是包裝的。根本沒有關閉td標籤。 – BoltClock 2013-04-08 14:58:24

回答

1

這是相對的第n個孩子到它的父。所以你說「第五img它的父母th」。你的html是狡猾的(如錯誤),但我認爲你應該嘗試定位th

+3

更確切地說,它是「父親中的第5個」img「,發生在」th「內。 「th」可能是也可能不是它的父母。 HTML對我來說似乎沒有錯,但結束標籤並不一致。 – BoltClock 2013-04-08 15:01:42

+0

@BoltClock正式註冊並更新 – 2013-04-08 17:03:45

0

我不工作,因爲您的th都沒有5張圖像。我想你想

table#OppPracticeOverview tr th:nth-child(5) img {...} 
0

在我來說,我犯了一個小錯誤

.someclassA .someclassB: nth-child(odd){ 

你可以看到,如上所述,someclassB:和n-child之間有一個空格。多數民衆贊成它.. 通過刪除空間,它開始工作:)

0

一些時間第n個孩子不行試試這個第n-的類型()

table#OppPracticeOverview tr th:nth-of-type(5) img 

,這是爲我工作