简体   繁体   English

如何使用 material-ui 使 reactjs 网站响应

[英]How to make reactjs website responsive using material-ui

I am working on reactjs project using material-ui.我正在使用 material-ui 处理 reactjs 项目。 Web-page is working perfect on desktop layout but when I switch layout to responsive (mobile).网页在桌面布局上运行完美,但是当我将布局切换到响应式(移动)时。 Than all the text and images merge in eachother.比所有的文本和图像都相互融合。 My question is this that how can I make my site responsive.我的问题是如何让我的网站响应。 Below is the code snippet with its layout image.下面是带有布局图像的代码片段。

 const useStyles = makeStyles((theme) => ({ main: { width: "100%", minWidth: "100%", }, grid1: { height: "100vh", minWidth: "100%", //backgroundImage: `url(${img1})`, backgroundColor: "khaki", display: "flex", flexDirection: "column", flexWrap: "wrap", }, img1: { backgroundSize: "contain", backgroundRepeat: "no-repeat", height: "100%", width: "100%", zIndex: "0", position: "relative", opacity: "0.7", }, font1: { zIndex: "1", fontFamily: "Crimson-Text", fontWeight: "bold", fontSize: "350%", position: "absolute", left: "30%", top: "40%", color: "white", }, font2: { zIndex: "1", fontFamily: "Crimson-Text", fontWeight: "bold", fontSize: "150%", position: "absolute", left: "40%", top: "53%", color: "white", }, btn1: { zIndex: "1", fontFamily: "Crimson-Text", fontWeight: "bold", //fontSize: "150%", position: "absolute", left: "35%", bottom: "20%", color: "inherit", variant: "outlined", borderRadius: "1px", background: "white", "&:hover": { color: "inherit", variant: "contain", background: "grey" }, }, btn2: { zIndex: "1", fontFamily: "Crimson-Text", fontWeight: "bold", //fontSize: "150%", position: "absolute", left: "50%", bottom: "20%", color: "inherit", variant: "outlined", borderRadius: "1px", background: "white", "&:hover": { color: "inherit", variant: "contain", background: "grey" }, }, })); const Home = () => { const classes = useStyles(); return ( <Grid container xs={12} sm={12}> <Grid item xs={12} sm={12} className={classes.grid1}> <img src={img1} className={classes.img1} alt="home1" /> <Typography className={classes.font1}>Shoes made from wool</Typography> <Typography className={classes.font2}>Now in new colors</Typography> <Button className={classes.btn1}>Shop Men</Button> <Button className={classes.btn2}>Shop Women</Button> </Grid> ); }; export default Home;
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
在此处输入图像描述

you can change here:你可以在这里改变:

main: {
    display:'flex',
    width: "100%",
    minWidth: "100%",
  }, 

and in the grid side:在网格侧:

<Grid container spacing={3}>
      <Grid item item xs={12} sm={6} className={classes.grid1}>/*or you an use item xs={6} sm={3}*/
        <img src={img1} className={classes.img1} alt="home1" />
        <Typography className={classes.font1}>Shoes made from wool</Typography>
        <Typography className={classes.font2}>Now in new colors</Typography>
        <Button className={classes.btn1}>Shop Men</Button>
        <Button className={classes.btn2}>Shop Women</Button>
      </Grid>
 

for better understanding you should follow that link为了更好地理解,您应该点击 该链接

you can arrange your grid any way you want when you try to squeeze the browser.当您尝试挤压浏览器时,您可以以任何您想要的方式排列您的网格。 it will make it responsive for various size of screens它将使其响应各种尺寸的屏幕

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

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