CSS - 目标div的最后一个实例

时间:2013-04-22 19:13:59

标签: html css css3 css-selectors

我有一个如下所示的div结构,我只想在页面上定位最后一个.pcontain,这样我就可以删除边框了 - 我该怎么办呢?

<div class="container">
    <div class="postcontainer">
        <div class="latest-posts">
            <div class="thumbnail"></div>
            <div class="pcontain"></div>
            <div class="more"></div>
        </div>
    </div>
    <div class="postcontainer">
        <div class="latest-posts">
            <div class="thumbnail"></div>
            <div class="pcontain"></div>
            <div class="more"></div>
        </div>
    </div>
    <div class="postcontainer">
        <div class="latest-posts">
            <div class="thumbnail"></div>
            <div class="pcontain"></div>
            <div class="more"></div>
        </div>
    </div>
    <div class="postcontainer">
        <div class="latest-posts">
            <div class="thumbnail"></div>
            <div class="pcontain"></div>
            <div class="more"></div>
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:9)

Working Fiddle

使用last child

.postcontainer:last-child .pcontain{ 
    background: black;
    color: white;
}

Read more about last-child here

答案 1 :(得分:2)

您可以使用last-child伪类,如:

.postcontainer:last-child .pcontain {
color: darkolive;
}

http://jsfiddle.net/ZZMZn/10/