Tips for achieving 100% width with React Material UI's <Grid>

https://i.sstatic.net/CIYrE.png

I'm attempting to expand this Grid component to be 100% in width so it fills the entire screen.

Javascript file

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
import './CodingTest.css';

const useStyles = makeStyles((theme) => ({
  grid: {
    height: '100%',
    margin: '0px',
  },
  paper: {
    padding: theme.spacing(2),
    textAlign: 'center',
    color: theme.palette.text.secondary,
    background: theme.palette.success.light,
    height: '100%',
  },
}));

export default function CodingTest() {
  const classes = useStyles();

  return (
    <div>
      <Grid container className={classes.grid}>
        <Grid item xs={12} md={6}>
          <Paper className={classes.paper}>1</Paper>
        </Grid>
      </Grid>
    </div>
  );
}

In my .css file, I've successfully made the component full width on the right side but there is still some padding remaining on the left, as indicated by the image above.

CSS

* {
  min-width: 100%;
}

.MuiContainer-root .MuiContainer-maxWidthLg {
  margin: 0px;
  padding: 0px;
  border: 0px;
  min-width: 100%;
}

@media (min-width: 600px) {
  .MuiContainer-root .MuiContainer-maxWidthLg {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 100%;
    max-width: 100%;
  }
}

@media (min-width: 1280px) {
  .MuiContainer-root .MuiContainer-maxWidthLg {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 100%;
    max-width: 100%;
  }
}

Answer №1

After setting up a codesandbox to analyze your code and examine the html, I made an interesting observation: https://i.sstatic.net/5Immo.png

I discovered that there was an 8px margin being added to the left side of the page within the body. To fix this, I included style="margin: 0px;" in the body tag found in index.html.

  <body style="margin: 0px;">

As a result, the layout now appears as follows: https://i.sstatic.net/4tpgK.png

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

Unable to use the search feature in the MKDOCS Material theme

After setting up an MKDOCS site with the 'material' theme and hosting it using an Azure Web App, I encountered an issue where the search bar does not work on the Azure web app. When the cursor is placed in the search field, it displays 'Init ...

JavaScript and the proper way to format the weekdays

Learning programming is new to me, so please bear with me. I am currently utilizing Informer, a reporting website that retrieves data from Datatel, a unidata database. My current task involves working on a computed column that only accepts Javascript and ...

Is there a way to eliminate the border of an image attribute pulled from an input field?

Seeking assistance with a persistent issue I'm facing. I have an input for an image and a script to display the selected image. However, when the input is empty, a frustrating black border appears around the image attribute. How can I remove this bord ...

Tips for testing screen orientation using jest and testing-library/react

While testing a component in nextJs using testing-library/react and jestJs, I encountered an error when trying to access "window.screen.orientation.type". The error message read: "TypeError: Cannot read properties of undefined (reading 'type')". ...

JQuery triggers multiple function calls when the window is resized

My current project involves the following tasks: - When the window's width is less than 700px and a user clicks on the gray bar at the bottom, a red menu should slide up and remain visible. - If the window's width exceeds 700px, clicking on the ...

Ensuring a Memory Leak-Free Environment: Tips and Tricks

Here is my code, and I'm curious if the delete function effectively destroys an object without causing any memory leaks: class Projectile extends MovableObject{ constructor(){ super(); this.speed = 2; this.geometry = new THREE.CircleGeome ...

What is the best method for performing cross-domain queries utilizing ajax and jsonp?

When attempting to send an ajax request to a specific URL, I encountered an error. Below is the code I used: $.ajax({ url: "http://webrates.truefx.com/rates/connect.html?q=ozrates&c=EUR/USD&f=csv&s=n", dataType : 'jsonp', ...

Employee plus Concave Authentication

After incorporating a module that uses Convex into my Clerk authentication application, everything seemed to work smoothly. However, I encountered an issue when attempting to refresh the page after logging into the new module. Suddenly, I received an error ...

Automatically resizing images in a canvas when their resolution exceeds the canvas size in HTML5

I am currently using Html5, fabric.js, and JavaScript to upload multiple images to a canvas. However, there are instances where the uploaded image size exceeds that of the canvas. I am looking for a way to ensure that the image is set to a fixed size. v ...

stop the page from refreshing when clicking on the map area

http://jsbin.com/iTeNiJIt/1/edit?output I currently have multiple map areas on my webpage. When a user clicks on any of these areas, I want to create an animation without refreshing the page. However, I am facing an issue where the page refreshes every ti ...

Incorporate additional query parameters into a dynamic route with React Router to enhance functionality

I am currently working on incorporating an optional query parameter to the end of a path in order to create URLs like this: "/user/1/cars?makeYear=2020" or "/user/1/cars". The relevant Route is defined as shown below. I have been having ...

In TypeScript, a subclass can be assigned as a value of a superclass-type, but it cannot be directly used as a parameter in a function that specifically

class Parent { str = 'a'; } class ParentExtended extends Parent { num = 1; } class MyClass { static property?: Parent static method (p: Parent): void {} static func?: (pParam: Parent) => void } const pe: ParentExtended = { str: &ap ...

What is the process for SpringBoot to extract the current user from ReactJS?

I am currently delving into the code of a Full-stack web application, which can be found at https://github.com/callicoder/spring-security-react-ant-design-polls-app. However, I am struggling to comprehend how Spring Boot identifies the current user who is ...

Adjust the <div> element to dynamically resize based on the user's browser changes

I need a div to adjust its width and height dynamically based on the browser dimensions when a user resizes their browser window. Implemented code following the provided suggestions: <!DOCTYPE html> <html> <head> <link rel="s ...

BEM CSS Element or variant

I am currently in the process of transitioning to BEM CSS and have created a component that I would like to have both small and large versions at the block level. I am struggling with determining which part should be considered the block and which should ...

React.JS error: Unable to iterate over movies in this.state due to incorrect data type

// English is not my strong suit, so please bear with me. Having trouble with a type error when trying to use an API to display data on a map? Feel free to reach out for help! Can you spot the issue in the code below? .then(data => This.setSt ...

Fixed top navbar in Bootstrap 4 remains collapsed, obscuring the content

I have tried numerous threads on Stack Overflow and also this one, but I still can't seem to get it right. My goal is to have a fixed navbar at the top using Bootstrap 4, but for some reason, the navbar keeps shifting upwards. I've even added pad ...

Regular expression to detect a space that is escaped

Given a string: rsync -r -t -p -o -g -v --progress --delete -l -H /Users/ken/Library/Application\ Support/Sublime\ Text\ 3/Packages /Users/ken/Google\ Drive/__config-GD/ST3 Attempting to find a regex pattern that matches spaces, but ex ...

Creating an Account with Firebase

I've created a function called signup in my web project that uses JavaScript to add a user to my Firebase database. The function works fine, but I'm encountering an issue when I try to redirect to another page at the end of the function - the use ...

What is the best way to utilize an HTML form input in order to update a value on a website that will affect all users?

I am relatively new to web development and I am currently working on a website that features a leaderboard. The goal is to allow users to input the number of points they have earned since their last log-in, with this value being added to their existing sco ...