0

How can one select all divs which have a child whose class is "test-class"?

Wow, this marked as duplicate of Is there a CSS parent selector?. I read that question and this question is really a duplicate... however, I and I suppose no one will find that badly titled question if she/wants to do what I am described in my title.

1) CSS has parent selector but we are seeking from something else

2) That question title would be Is there a CSS child selector?

4

2 回答 2

3

编辑:为了读者清楚起见,最初的问题是

如何选择测试类中的所有 div 并且有一个 child ?

你不能,因为在 CSS 中(还没有)父选择器或上一个兄弟选择器。

您只能定位下一个兄弟姐妹或孩子(然后是后代)...

只有右下,没有左上_ _ _

请注意,请尽可能不要使用 W3SCools(请阅读原因),对于选择器,请参阅 W3C 官方文档:

CSS2 选择器

CSS3 选择器

CSS4 选择器 -草稿

当 CSS4 准备好时,如果它像现在记录的那样,那么合适的选择器将是:

E! > F

F 元素的 E 元素父级

确定选择器 + 子组合器的主题

然后你就可以制作一个像

.test-class div! > *

读作:每个DIV里面都有东西(一些孩子)并且是test-class

于 2013-05-03T14:16:26.797 回答
-2

您可以按数字选择 parent-div(“test-class”)的孩子。所以要选择所有第一个孩子:

.text-class:nth-child{/*code*/}

为了确保所有子 div 都被选中(我会做尽可能多的子 .text-class div):

.text-class:nth-child, .text-class:nth-child(2), 
.text-class:nth-child(3), .text-class:nth-child(4){/*code*/}

顺便说一句,它在列表中,希望它对你有用!

于 2013-05-03T14:20:56.660 回答