:not(:first-child)和:not(:first-of-type)不工作

Jos*_*ker 33 html css

我有一种树系统.我要做的是给所有父母一个保证金,除了第一个.这是我的HTML:

<div id="someDivID">
    <div class="theBody">
        <div class="someContainer">
            <div id="someItem" class="someItemClass">
                Test
            </div>
        </div>
        <div class="someContainer">
            <div id="someItem2" class="someItemClass">
                Test2
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我的CSS:

#someDivID
{
    width: 400px;
}

#someItem,
#someItem2
{
    border: 1px solid #000;
    padding: 1px;
    margin-bottom: 2px;
    clear: both;
    overflow: auto;
}

.someItemClass
{
    background-color: #0077FF;
}

.someItemClass:not(:first-of-type)
{
    margin-top: 50px;
}
Run Code Online (Sandbox Code Playgroud)

现在,我.someContainer有背景颜色,但第二个.someContainer没有上边距.如果我删除:first-of-type它的工作原理.:first-child也不起作用.

这是我的jsfiddles:

随着first-of-type:http://jsfiddle.net/JoshB1997/zsu2o3cg/

随着first-child:http://jsfiddle.net/JoshB1997/zsu2o3cg/1/

Edd*_*Edd 64

那是因为他们不是兄弟姐妹.

如果您将:not选择器更改为父div,它将起作用.

.someContainer:not(:first-of-type)
{
    margin-top: 50px;
}
Run Code Online (Sandbox Code Playgroud)

小提琴 - http://jsfiddle.net/ayhpkphw/