【问题标题】:Parent parent selector nested in stylus嵌套在手写笔中的父父选择器
【发布时间】:2016-05-25 09:17:03
【问题描述】:

当它嵌套在伪选择器中时,我试图在 Stylus 中获取父选择器。因此,虽然我可以在第一次嵌套中执行 &-image,但我似乎无法让它在 &:hover 中工作

.post-news
  &-image
    display: none
  &:hover
    &-image // this isn't working
      display: block

我理解为什么它不起作用,因为 & 不再引用 .post-news。我尝试了这里列出的选择器http://stylus-lang.com/docs/selectors.html,例如:

../-image
/-image
^[0]-image

但到目前为止我无法让它工作;我不确定我需要哪一个。我错过了什么?

【问题讨论】:

    标签: css stylus


    【解决方案1】:

    根据我的理解,您要查找的最终选择器是 .post-news:hover .post-news-image,如果正确,您可以像下面的 sn-p 一样进行操作。

    .post-news
      &-image
        display: none
      &:hover
        & ^[0]-image
          display: block
    

    说到 Stylus,我自己也是一个初学者,但据我了解,^[0]-image../-image 不能按预期工作的原因是因为 Stylus 编译器将它们视为某种级别的移动up 命令,因此它实际上与直接位于.post-news 下的&-image 相同。因此,正常的嵌套行为(即,.post-news:hover 添加到嵌套选择器的前面)不会发生。明确添加& 似乎可以解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 2013-03-19
      • 2017-09-15
      • 2012-09-22
      • 2021-07-14
      • 1970-01-01
      • 2014-05-26
      相关资源
      最近更新 更多