2016-01-22 67 views
2

我想使用最后一种类型选择两个元素,但我不知道正确的语法是什么。如果这是html:具有多个选择器的CSS最后一种类型

<div class="Box"> 
    <book class="small"/> 
    <book class="small"/> 
    <notes/> 
    <notes/> 
    <toy class="small"/> 
    <toy class="small"/> 
</div> 

我想选择最后一本书和最后一个玩具,语法是什么?我虽然它会:

div.Box book.small, toy.small:last-of-type { } 

但这显然是不正确的。

+0

刚刚过去的书和玩具最后还是过去书本小班和小类中的最后的玩具? – Harry

+0

你为什么不在'book'中使用':last-of-type'? – j08691

+0

@ j08691我想这回答我的问题。这就是我想要做的。 o,我假设你建议我需要把“div.Box book.small:最后一个类型,toy.small:最后一个类型”? –

回答

1

你的财产last-of-type同时适用于选择:

div.Box book.small:last-of-type, toy.small:last-of-type 
+1

谢谢。这正是我所需要的。我以为我可以添加两个选择器,然后应用最后一个类型。 –

4

尝试

div.Box book.small:last-of-type, 
div.Box toy.small:last-of-type { 
    /* styles */ 
} 

这里是一个Fiddle

+0

这太好了。谢谢! –

相关问题