2015-11-16 27 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选择器,它隐藏了第二个孩子的边界。

相关问题