Tips for creating a responsive ReactJS website with Material-UI

I've been working on a reactjs project with material-ui, and everything looks great on desktop. However, when I switch to the mobile layout, all the text and images start overlapping. I'm wondering how I can make my site responsive. Below you'll find the code snippet along with an image of the layout.

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>
https://i.sstatic.net/zaNC8.png

Answer №1

Modify your settings here:

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

Also, adjust the grid layout as follows:

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

To enhance your understanding, refer this link

You have the flexibility to customize your grid layout for different screen sizes by adjusting it accordingly when resizing the browser window.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Finding unique data stored in separate JSON files and loading them individually may require using different methods for

I have two JSON files named marker.json and marker.json0 that contain different latitude and longitude coordinates. To load them, I need to rename .json0 to .json (and vice versa), so that the new data from marker.json0 now resides in marker.json. This way ...

Tips for integrating Stripe into a React test

I am currently conducting a test on a React component that utilizes Stripe, and I am unsure about the best way to structure the test. An error message has been popping up as follows: Error: In order to use react-stripe-elements, ensure that Stripe.js ( ...

The striped color override feature in Bootstrap appears to be malfunctioning in Internet Explorer 8

I have come across several discussions regarding this topic with various suggestions. My current objective is to make the alternating rows in Bootstrap (2.3.2) appear darker in Internet Explorer 8. To achieve this, I attempted to override the style by impl ...

What could be causing the date input to appear oddly compressed solely on iPhone devices?

Click here to access the website, and view the code. The layout appears fine on desktop, as shown in this screenshot. However, on an iPhone, the date input gets collapsed despite being set to take up the full width of its parent div. Here is a screenshot ...

There seems to be an issue as `props.dogs.map` is not

I'm currently working on a project where I have a search bar and a card that displays a dog's name. My goal is to use the search bar to filter the displayed dog names. However, I ran into an issue where I'm getting the error "props.dogs.map ...

Utilizing image backgrounds for hyperlinks in the Android browser

Encountering a minor issue with some <a> tags that have images as background, and the text inside the tags is indented using CSS. However, on the Android browser, part of the string used in HTML appears to cover the background image within the area o ...

What is the best way to set up a proxy between Partytown and Gatsby during deployment on Netlify?

Trying to integrate GTM with Partytown has resulted in a CORS error for me. Does anyone know how to troubleshoot this issue? Here is the content of my gatsby-ssr.js file: import React from "react"; import { Partytown } from "@builder.io/par ...

CSS layout: The full-width header should align its left margin with the centered content-div

Can someone help me out with a solution to my problem? My page has a 1040px centered div for content, menu, and footer. I want the header image to align with the left margin of the content div and expand towards the right side for higher screen resolutio ...

ReactJS encountered an error: Module '@progress/kendo-scheduler-react-wrapper' could not be located

![kendo ui npm issue]https://i.stack.imgur.com/5cERD.jpg Struggling with a 'can't resolve' error when attempting to integrate this kendo-ui package. ...

Encountered a parsing error while attempting to include the navigation bar page

<?php echo <<< END <!DOCTYPE html> <!-- --> <html> <head> <title>Nav</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0 ...

Having trouble with the functionality of JQuery drop feature?

As I delve into implementing drag and drop functionality with JQuery, I encounter a peculiar issue. I have set up 3 'draggable' divs and corresponding 3 'droppable' divs. The intended behavior is for each draggable element to be accepte ...

The component is not being displayed due to issues with nested routing

When attempting to display the CollectionPage Component from the ShopPage component as a nested route that receives match as a param, I encountered an issue where the page was empty and displayed an error message. The collection page was not rendering with ...

How can I personalize the preview feature in a Bootstrap rich text editor?

Currently, I am utilizing Bootstrap's rich text editor by this method $('#editor').wysiwyg();. Utilizing AJAX, I am passing the HTML content created by .wysiwyg to save it in the database. Later on, I plan to retrieve the saved HTML data to ...

Mastering the integration of an array of objects with the ej2 Syncfusion data grid

Trying to figure out how to map a complex array of objects into the ej2 Syncfusion React data grid. Here is an example of my array: [ { "id_team": "1",, "team_name": "Testing", "adviser": " ...

Conflicting search data in a React Ant Design Form

As a newcomer to React, I am using the Ant Design framework for my application. I am currently facing an issue with implementing a book name and price search after displaying details. I'm unsure of the correct approach to take. Can anyone provide guid ...

Getting data from a list in an SPFX solution: A step-by-step guide

I have 3 files - RequestSHP.tsx, WebPart.ts, Exekucie.tsx. I'm attempting to populate a dropdown with data from a list, but encountering a "404 (Not Found)" error. Here is my RequestSHP.tsx -> import {sp} from '@pnp/sp/presets/all'; exp ...

Incorporating an external JSX file into an HTML page in a React project

I have a React code in my js/script.js file. My HTML page's head tag is structured like this: <head> <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="06746367657246373328302834" ...

Creating Repeating nth-child Patterns with CSS

Currently grappling with a unique CSS challenge related to patterns. Here's what I'm aiming for: For LI 1-3 = green background For LI 4-6 = red background For LI 7-9 = blue background This sequence should repeat as follows: LI 10-12 = green ...

Using ES6, when utilizing array map in ReactJS, the function does not produce a return value

One challenge I'm facing involves mapping an array to find a specific string value. Unfortunately, despite my efforts, the map function is not returning anything as expected. class Application extends React.Component { constructor(){ super(); ...

What's the process for converting offsetX and offsetY pixel coordinates to percentages?

Currently, I am working on a project where I need the offsetX and offsetY coordinates to be displayed in percentage (%) format while hovering over a div element. By default, these coordinates are shown in pixels. Here is an example of the structure: < ...