只有孩子当多个父亲有那个唯一的孩子 [英] only child when more than one parent has that only-child

查看:233
本文介绍了只有孩子当多个父亲有那个唯一的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次发布,当前学生学习CSS伪选择器。

first time posting, current student learning CSS pseudo-selectors.

问:如果元素是两个或更多不同父母的唯一子只使用一个孩子只对一个父母?

Q: if an element is an only-child to two or more different parents, how do you use only-child with respect to only one of the parents?

上下文:我在CSS小餐馆的唯一的儿童课。布局如下:苹果在盘子上,腌菜在盘子上,在盘子上腌制,大橙子和小橙子在盘子上,并在桌子上腌制。我应该使用只有孩子选择板上的苹果和板上的泡菜。在这种情况下的盘子是父元素。

Context: I am on CSS Diner on the only-child lesson. The layout is as follows: apple on a plate, pickle on a plate, pickle on a bento, large orange and small orange on a plate, and pickle on the table itself. I am supposed to use only-child to select the apple on the plate and the pickle on the plate. The plates in this scenario are the parent elements.

显然,苹果在板上会是苹果:只有孩子。我被困在腌菜上,但是,因为它是一个只有一个板和一个底盘的孩子。我的想法是简单地使用板> pickle,但它的声音从我应该能够以这种方式用唯一的孩子选择器。

Obviously the apple on the plate would be apple:only-child. I'm stuck on the pickle, however, because it is an only child of both a plate and a bento. My thought would be to simply use plate>pickle, but it sounds from the lesson that I should be able to do this somehow with the only-child selector.

有没有办法只使用 - 孩子选择板上的泡菜,但不是在bento?

So, is there a way to use only-child to select the pickle on the plate but not on the bento?

谢谢!

推荐答案


问:如果元素是两个或多个不同父项的唯一子元素,的父母?

Q: if an element is an only-child to two or more different parents, how do you use only-child with respect to only one of the parents?

A:您指定要匹配子节点的父节点,与子组合器> 。

A: you specify which parent you want to match the child with respect to, in conjunction with the child combinator >.

在这种情况下,您可以安全地使用 plate& :only-child ,因为只有苹果和腌汁是他们母板的唯一的孩子;虽然有一盘橙子,橙子不是唯一的孩子,因此他们不会匹配:only-child

In this case, you can safely get away with plate > :only-child since only the apple and pickle are the only children of their parent plates; although there is a plate of oranges the oranges aren't the only children, and so they won't match :only-child.

这篇关于只有孩子当多个父亲有那个唯一的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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