简体   繁体   English

在不同级别的元素中选择具有给定类型的最后一个子级

[英]Selecting the last child with the given type among different levels of elements

I have a dynamically generated snippet of HTML which could look something like this (but may have many different levels of nesting): 我有一个动态生成的HTML片段,看起来像这样(但可能有许多不同级别的嵌套):

<div class="content">
    <div class="thing"></div>
    <div>
        <div class="thing"></div>
        <div class="thing"></div>
    </div>
    <div>
        <div>
            <div class="thing"></div>
            <div class="thing"></div>
        </div>
    </div>
    <div>
        <div class="thing"></div>
    </div>
</div>

I would like a CSS expression to select the last element with the class thing that is a (not necessarily direct) child of .content . 我想要一个CSS表达式来选择具有类thing的最后一个元素,该类是.content的(不一定是直接的)子元素。

:last-child or :last-of-type won't work because they match if the element is the last child (of a certain type) of their parent, in which case it will match more than .thing . :last-child:last-of-type将不起作用,因为如果该元素是其父级的最后一个子级(某种类型),则它们匹配,在这种情况下,它将匹配多于.thing

Is there a CSS expression I can use to do this? 有没有我可以用来做这个的CSS表达式?

这个问题的答案表明,遗憾的是,这在CSS中是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM