阅读(2411) (2)

styled-components 支持的CSS

2020-07-24 16:31:11 更新

在样式化的组件内,我们支持所有CSS加嵌套。由于我们生成的是实际的样式表而不是内联样式,因此CSS中的所有工作都可以在样式组件中使用!



  > p {
    /* descendant-selectors work as well, but are more of an escape hatch */
    text-decoration: underline;
  }
  /* Contextual selectors work as well */
  html.test & {
    display: none;
  }
`;
render(
  <Example>
    <p>Hello World!</p>
  </Example>
);


&符(和)替换为该样式化组件的生成的唯一类名,从而使复杂的逻辑变得容易。