2012-11-10 44 views
1

我的標記是CSS - 選擇第三DL

<div class="gallery"> 
<dl class="item">content 1</dl> 
<dl class="item">content 2</dl> 
<dl class="item">content 3</dl> 

<br style="clear: both"> 

<dl class="item">content 4</dl> 
<dl class="item">content 5</dl> 
<dl class="item">content 6</dl> 
</div> 

現在我想在列表中選擇第三DL。 內容3含量6,但這CSS僅選擇內容3但不內容6。 「dl」之間的「br」使某些東西破裂。

.gallery :nth-child(3) { 
    margin-right: 0; 
} 

有什麼想法嗎?

謝謝

回答

1

使用dl:nth-of-type(3n)而不是排除br

.gallery dl:nth-of-type(3n) { 
    margin-right: 0; 
} 

或者使用另一個:nth-child()規則適用通關後,未來dl,並擺脫br的,因爲它不是需要:

.gallery dl:nth-child(3n) { 
    margin-right: 0; 
} 

.gallery dl:nth-child(3n+1) { 
    clear: both; 
} 
+0

哇!完美的作品!謝謝你,BoltClock! – efendi

+0

我可能會建議使用其他技術?這不需要額外的HTML標記。 http://pathfindersoftware.com/2007/09/developers-note-2/ –

+0

@BoltClock與OP確認他們沒有使用IE瀏覽器! ':P' –