2010-09-09 68 views
1

我需要覆蓋在我的樣式表中使用jQuery定義的定義:最後孩子樣式。 我打算使用css和jQuery組合的最小標記,其中圍繞「容器內容」的結構被附加到文檔就緒的div上。覆蓋:使用jQuery的第一孩子僞類風格

<div id="title-some-impact"><!--Vertical container title--></div> 
    <div class="container-content-wrapper"> 
     <div></div> 
     <div class="container-content"><!--Actual container content--> 
      <div class="sub-container-content"></div> 
     </div> 
     <div style=""></div> 
    </div> 
    <div style="clear: both;"></div> 
</div> 

我使用的容器內容包裝的第一和最後一個div添加使用CSS圓角,就像這樣:

.container-content-wrapper>div:first-child { /* rounded corners top */ 
    width: 930px; 
    height: 16px; 
    background: url(../Images/top-rounded-corners.png) top no-repeat; 
} 

.container-content-wrapper>div:last-child { /* rounded corners bottom */ 
    width: 930px; 
    height: 33px; 
    background: url(../Images/bottom-rounded-corners.png) top no-repeat; 
} 

在某些情況下,我需要改變底層的背景圖片使用jQuery/JavaScript到目前爲止失敗了。我試過使用: $('。container-content-wrapper> div:first-child')。css('background','some other link'); 另外,添加指向另一個圖像的另一個類不起作用。

如何覆蓋樣式表中使用jQuery定義的最後子樣式?

+0

你可以請你展示你的完整的jQuery處理程序,你嘗試和加載背景?另外,你如何在你的html內部加載你的jQuery,在一個外部的.js文件或'

0

其實我最初犯了一個錯誤的目標的風格需要被取代的股利。這只是做出正確選擇的問題。

僅供參考,我以解決它:

$('.container-content-wrapper:has(.sub-container-content)') 
.addClass('container-content-wrapper-for-sub'); 

其中容器內容包裝換子都有這種風格如下.container化內容包裝定義> DIV:最後-child

.container-content-wrapper-for-sub>div:last-child { 
/* rounded corners bottom for subsection */ 
    background: url(../Images/bottom-rounded-corners-extra-gray.png); 
}