2015-11-16 26 views
-1

請檢查小提琴:http://jsfiddle.net/C23g6/1255/如果我給最後一個元素顯示none,如何選擇最後一個div?

我想最後一個子(7777)上邊框是顯示器無法比擬的。

我試過了,但我不能請給我解決方案。

只有通過CSS

CSS 
.common.true{ 
    display: block; 
    border-top: 1px solid red; 
} 
.common{ 
display: none; 
} 
.true:last-child{ 
border-top: none; 
} 

我不希望最後一個子邊界不顯示。但不使用第n個孩子。一些其他的方式

+0

什麼是選擇7777 DIV的原因是什麼?它總是最後一個孩子嗎?或者有沒有一個特定的原因,你不能使用'nth-child()'或'nth-last-child()'? – jbutler483

+0

您正在搜索':last-of-type' http://stackoverflow.com/questions/7298057/css-last-child-selector-select-last-element-of-specific-class-not-last-child -一世 – eMarine

回答

4

第一件事,如果你顯示:沒有最後一個元素,那麼你如何使用該元素(隱藏元素)的CSS。

如果你想獲得Id或類(屬性)來執行該操作,你應該選擇js或jquery。

第二件事,最後孩子將是8888,但要與倒數第二個孩子的事,然後用這個,它可能工作:

.common:nth-last-child(2){ 
     border-top:none !important; 
    }`enter code here` 
2

你必須在HTML中的HTML.Your最後一個子一個基本的錯誤是8888,你想隱藏7777.Use的邊框頂部以下內容:

<div id="my-section"> 
    <div class="common true">1111</div> 
    <div class="common">2222</div> 
    <div class="common true">3333</div> 
    <div class="common true">4444</div> 
    <div class="common true">5555</div> 
    <div class="common true">6666</div> 
    <div class="common true">7777</div> 
    <div class="common">8888</div> 
</div> 
.common.true{ 
     display: block; 
     border-top: 1px solid red; 
} 
.common{ 
    display: none; 
} 
.true:last-child{ 
    border-top: none; 
} 
#my-section .common:nth-last-child(2){ 
    border-top:none !important; 
    } 

我添加了一個新的CSS選擇器,它隱藏了第二個孩子的邊界。

相關問題