【问题标题】:Conditional child animations based on parent CSS state (with styled-components for React)基于父 CSS 状态的条件子动画(带有用于 React 的样式组件)
【发布时间】:2017-02-25 18:58:57
【问题描述】:

对于 React 使用 styled-components,是否有任何替代方法

.btn:hover:not(.inactive)>.btn-top,
.btn.active:not(.inactive)>.btn-top {
  z-index: 2;
  /* transform here */
}
.btn:hover:not(.inactive)>.btn-bottom,
.btn.active:not(.inactive)>.btn-bottom {
  z-index: 1;
  /* transform here */
}

(使用嵌套条件选择器确保所有动画在同一个 DOM 中,但不同的 z-index 级别正确运行/完成)?

(对不起,标题长度。没有代表创建样式组件标签。)

【问题讨论】:

    标签: javascript css reactjs styled-components


    【解决方案1】:

    :hover:not(.inactive) > &, .active:not(.inactive) > & 用作 (Sass) 选择器。

    谨慎使用。在多个父母有条件类的情况下(.active.inactive 这里),像.active & 这样的东西可能会产生副作用。然后,另一种选择是pass React props to descendants for conditional styling with styled-components

    geleen(维护者)在 gitter 上回答。在此处添加以完成和 google-fu。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-03
      • 2014-12-11
      • 2020-11-04
      • 2018-08-19
      • 2018-12-21
      • 1970-01-01
      • 2017-01-19
      • 2021-10-22
      相关资源
      最近更新 更多