简体   繁体   English

如何在antd react中将不同的样式应用于不同的屏幕尺寸?

[英]How to apply different styles in different screen sizes in antd react?

I have used material-ui for some of my prev projects and know i want to use antd. 我已经在一些上一个项目中使用了material-ui,并且知道我想使用antd。 In material-ui we can apply different styles for a div in different screen sizes, 在material-ui中,我们可以在不同的屏幕尺寸下为div应用不同的样式,

const styles = theme => ({
    main: {
        [theme.breakpoints.only('md')]: {
            height: '360px',
        },
        [theme.breakpoints.only('sm')]: {
            height: '280px',
        }
    }
});

How we can accomplish that in antd? 我们如何在antd中实现这一目标?

AntD uses ordinary CSS or LESS to accomplish this, which means you can't use inline styles as in your question unless you use some 3rd party styling plugin. AntD使用普通的CSS或LESS来完成此操作,这意味着除非使用某些第三方样式插件,否则您不能像问题中那样使用内联样式。

The AntD default theme provides the breakpoint variables: AntD默认主题提供断点变量:

@screen-xs              : 480px;
@screen-sm              : 576px;
@screen-md              : 768px;
@screen-lg              : 992px;
@screen-xl              : 1200px;
@screen-xxl             : 1600px;

These can then be used in LESS files for standard media queries. 然后,可以在LESS文件中将它们用于标准媒体查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM