css - 我可以在 React 中使用样式化组件实现以下条件媒体查询吗?

标签 css reactjs styled-components

我正在尝试将 wrapper 类添加到 React 中的样式化组件。有什么我可以实现它以便生成如下 CSS 吗?

.test-class {
    color: red;
    font-size: 40px;
}

@media (max-width: 600px) {
    .wrapper .test-class { 
       color: blue;
       font-size: 30px;
    }
}

像这样

const Content = styled.div`
    color: red;
    font-size: 40px;

    @media (max-width: 600px) {
       .wrapper {
            color: blue;
            font-size: 30px;
       }
    } 
`;

谢谢!

最佳答案

这里有一个示例模板可以做到这一点

const Content = styled.div`
  background: papayawhip;
  height: 3em;
  width: 3em;

  @media (max-width: 700px) {
    background: palevioletred;
  }
`;

render(
  <Content />
);

有关更多信息,请参阅 - https://www.styled-components.com/docs/advanced

关于css - 我可以在 React 中使用样式化组件实现以下条件媒体查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49234979/

相关文章:

javascript - 在 Canvas 上显示Google字体

javascript - Heroku Google OAuth 错误

javascript - 如何在 native react 中每秒生成一次随机数?

reactjs - 带有 animate.css 的样式组件

javascript - Autosuggest renderInputComponent - inputProps 类型的属性 'onChange' 不兼容

css - 当我运行 grunt 时,我的 css 没有更新

html - 浏览器图像渲染中断 css 内联 block 布局

css - 如何自定义 material-ui Accordion 组件的行为/样式?

reactjs - 如何将自定义字体添加到样式组件中的主题提供者?

html - 将图像放置在不规则形状的 div 中