“如果第一个孩子是"的CSS参数 [英] CSS argument for "if first child is"

查看:109
本文介绍了“如果第一个孩子是"的CSS参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在div内需要一个CSS选择器,但我希望它仅选择该元素在该div内特定类的第一个元素时的元素.

I need a CSS selector for inside a div but I want it to only select the element if its the first element of a specific class inside that div.

推荐答案

您的标题暗示如果第一个孩子是":div > .test:first-child将选择任何<div> if 中的第一个孩子的类为test.

As your title implies "if first child is": div > .test:first-child will select the first child of any <div> if it has the class test.

但是,如果<div> 的第一个子代没有类,那么它将不会继续搜索<div>,直到找到一个子类test -它什么都不会匹​​配.我不确定那是否就是您想要的.

But if the first child of the <div> doesn't have the class test, then it won't continue searching the <div> until it finds a child with the class test — it just won't match anything. I'm not sure if that's what you want.

这篇关于“如果第一个孩子是"的CSS参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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