【问题标题】:Element:hover doesn't affect child元素:悬停不影响孩子
【发布时间】:2021-06-19 10:33:48
【问题描述】:

我正在为我的学习路径编写一个网站,但遇到以下问题:
当我悬停&__item 时,动画属性不会以&__selection 的样式出现...

sass 代码:

&__item {
  /*...*/

  __selection{
    /*...*/
  }

  &:hover &__selection {
    animation: animSelect 800ms ease-in-out 0ms 1;
  }
}

【问题讨论】:

    标签: sass


    【解决方案1】:

    您正在使用 BEM 命名约定,针对 __selection 类有几种方法可以做到这一点,这个 stackoverflow answer 也很好地涵盖了这个问题,现在这些是我的猜测

    &__item {
      /*...*/
    
      __selection{
        /*...*/
      }
    
      &:hover __selection { //more of a normal css solution
    
        animation: animSelect 800ms ease-in-out 0ms 1;
    
      }
    }
    
    

    
    .item{ 
    
        &__selection {
             /*...*/
        }
    
        &:hover & {
            &__selection  {
                 /*...*/
            }   
        }
    }
    
    

    【讨论】:

      猜你喜欢
      • 2013-08-01
      • 2012-06-24
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2021-01-15
      • 2019-08-12
      相关资源
      最近更新 更多