首页 > 解决方案 > 另一个类中包含的第一次出现的类的 CSS 选择器

问题描述

我想访问包含在类 y 中的 class=x 的第一个元素。我有这个作为我的选择器 '.x .y' 但这会选择类 x 中包含的类 y 的所有元素。我只想要第一个。我怎么能用选择器做到这一点?

标签: css-selectors

解决方案


像这样的东西应该工作:

.x .y:first-of-type{
  /* Your CSS code here */ 
}

推荐阅读