简体   繁体   中英

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. In material-ui we can apply different styles for a div in different screen sizes,

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

How we can accomplish that in 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.

The AntD default theme provides the breakpoint variables:

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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