如何将媒体查询添加到 React CSS 对象?

问题描述

目前我有这个:

const ButtonStyles = {
    color: 'red',}

但我想为移动设备添加媒体查询,它看起来像这样吗?:

const ButtonStyles = {
    color: 'red','@media (max-width: 900px)': {
        color: 'blue',}
}

如果语法不是这种格式,那应该怎么做?

解决方法

根据此discussion,您不能将媒体查询与 react css 对象一起使用。您必须使用带有类名或其他外部模块(如样式组件)的样式表。