css第n个来自类元素的孩子 [英] css nth child from element with class

查看:98
本文介绍了css第n个来自类元素的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种方法可以从具有特定类的元素中选择(使用CSS)第n个孩子.例如,对于以下内容,如何选择带有id="this"li元素(出于说明目的而显示)?所以基本上我想说class="selected"

I there a way of selecting (using css) the nth child from an element with a certain class. For example, for the following, how could I select the li element with the id="this" (shown for explanation purposes)? So basically I want to say the 2nd element from the element with class="selected"

<ul>
    <li></li>
    <li class="selected"></li>
    <li></li>
    <li id="this"></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

推荐答案

实际上,您可以使用+选择器.它有点脏,但是可以用在您的情况下.您所需要做的就是知道所需元素的确切位置.

Actually you could do with + selector. It is a bit dirty, but works in your case. All you need is to know the exact position of element you need.

.selected + li + li(根据需要添加+ li次)

这篇关于css第n个来自类元素的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆