The children of the <Grid item> component in material-ui are overlapping the parent because they have a width of 100%

One issue I'm facing is that when I have children with full width in a Grid item, they end up overlapping to the right side of their parent.

To illustrate this problem, here's the code: https://codesandbox.io/s/rn88r5jmn

import React, { Component } from "react";
import { Paper, Grid, Button } from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
class Demo extends Component {
  render() {
    const { classes } = this.props;
    return (
      <Paper>
        <Grid container spacing={16}>
          <Grid item xs={6}>
            <Button variant="raised" fullWidth className={classes.button}>
              asdf
            </Button>
          </Grid>
          <Grid item xs={6}>
            <Button variant="raised" fullWidth className={classes.button}>
              asdf
            </Button>
          </Grid>
        </Grid>
      </Paper>
    );
  }
}
const styles = theme => ({
  button: {
    margin: theme.spacing.unit
  }
});
export default withStyles(styles)(Demo);

The output of the above code can be seen in the image below: https://i.sstatic.net/pMiQy.png

Answer №1

The issue lies not with the fullWidth prop, but rather with the margin being applied to the buttons. You can modify it like this:

Visit this link for a solution

import React, { Component } from "react";
import { Paper, Grid, Button } from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";

class Demo extends Component {
  render() {
    const { classes } = this.props;
    return (
      <Paper className={classes.paper}>
        <Grid container spacing={16}>
          <Grid item xs={6}>
            <Button variant="raised" fullWidth>
              asdf
            </Button>
          </Grid>
          <Grid item xs={6}>
            <Button variant="raised" fullWidth>
              asdf
            </Button>
          </Grid>
        </Grid>
      </Paper>
    );
  }
}

const styles = theme => ({
  paper: {
    padding: theme.spacing.unit
  }
});

export default withStyles(styles)(Demo);

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

When building with Angular using the "ng build" command, the JavaScript file names are altered

I'm currently learning Angular and I've noticed that when creating a new project with Angular CLI, files like runtime.js, polyfills.js, main.js, styles.css are generated. However, after running the ng build command, similar files can be found in ...

``I am having trouble with my object key mapping when it is based on

https://i.sstatic.net/3uIeW.png I attempted the following code but it did not work as expected: Object.keys(singleproductdetails).map(function(detail, id) { return ( <div> <ul ...

Unable to locate the module name loaded using require() function

Within my React file, I am importing a Javascript file like this (I am using Typescript): let FloDialog = require('../public/js/flo-dialog.min'); Afterwards, I declare a property for the dialog class: dialog: FloDialog = null; It is important ...

Issue with running npm start due to conflicting versions of Babelloader

I have Npm installed on my MacOS, and I keep encountering an ELIFECYCLE error after running either npm run start or npm start. When running the commands, I get the following hints pointing to a project dependency tree issue: [0] It seems to be related to a ...

"Exploring the possibilities of managing currency input in Ionic 3 using

In my Ionic 3 App, I am looking for a way to properly format currency input fields. For example, if I enter 10,000, I want it to display as PHP 10,000.00, and if I enter hundreds, it should show as PHP 100.00. Additionally, I need to handle the backspace ...

unique hyperlink to an external style sheet

element, I came across this line in the header of a web page that was generated by a program. Any thoughts on what significance the number and ID serve in this stylesheet link? <link rel="stylesheet" type="text/css" href="css/contact.css?4131768016" ...

Managing a multitude of instances in Three.js

While working on a scene in three.js that includes a high quantity of instances (around 2000) with 200-300 vertices each, I integrated some postprocessing effects using the EffectComposer. However, I noticed that the performance has been slowing down. Is ...

Node.js HTTP Server suddenly halts after a period of time

Question: I posted a similar inquiry on Super User regarding my Node.JS server on a RaspberryPi running Debian. Despite not receiving an answer there, I believe this platform may provide insight given the code-related nature of the issue. My Node.JS serve ...

How about a fading effect for the select box?

I'm currently working on creating a select tag that opens its options slowly with a fade in, fade out effect when the user clicks on "Actions." I've attempted to use jQuery for this feature but haven't had any luck. Here's my code: &l ...

Experiencing an internal server error while trying to make a post on my website, yet strangely it's not

Having trouble understanding why my server is struggling to fulfill a post request. The JSON below works perfectly fine in Postman: { "name": "post11111111111", "images": "image/path", "link": "https://etsy.com", "info": "this is a painting", "p ...

The problem lies in the execution of the $.getJSON function - the data is successfully converted from JSON to

My current task involves retrieving data from a json file hosted on a server, storing it in a global array, and then utilizing it in vue to iterate through the list. However, I am encountering an issue where even though the array is populated when printed ...

Choosing classes with BEM convention

I've been working on implementing the BEM naming convention, and I'm facing a challenge with styling a "tooltip" block using different themes. For example, applying the "default" theme like this: <div class="tooltip tooltip_theme_default"> ...

Can React refs be safely accessed within a function wrapped with window.requestAnimationFrame?

My understanding of React and HTML rendering behavior is not complete, leaving me unsure about the possibility of a potential issue with React refs becoming null if accessed from a function wrapped in window.requestAnimationFrame. This function could be ...

Step-by-Step Guide for Attaching Table Legs

I believe that the four legs should be an integral part of the table, rather than just added on like an afterthought. What would be the best way to create new instances of legs and attach them in a way that makes the back legs look slightly smaller than t ...

What steps should I take to address the bug in my create react app?

What steps can I take to resolve the bug in create react app? Every time I try running the command "npx create-react-app my-app --template typescript," I encounter the error shown in the image. ...

"Dynamically generated websites, backend processing, React framework Nextjs, Content Management System WordPress

I'm interested in creating a primarily static site using Next.js, but I also need the ability to provide customers with price estimates based on their specifications. The calculation process needs to be kept private and not exposed to anyone else (oth ...

Dropdown box with search functionality in twig

Here is the structure of my form: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('Name') ->add('Occupation'); } This is what my edit.html.twig lo ...

Using jQuery to iterate through a JSON array and extract key/value pairs in a loop

I want to create a loop that can go through a JSON array and show the key along with its value. I found a post that seems similar to what I need, but I can't quite get the syntax right: jQuery 'each' loop with JSON array Another post I cam ...

`Even though I specified `{cache: $templateCache}` in the $http call, the directive is still showing $templateCache as

I have two HTML pages named snippet1.html and snippet2.html. I want to use them within my directive in order to add multiple templates using a single directive. To achieve this, I initially tried adding the HTML templates within <script> tags and as ...

Securely store files by encrypting them with Node.js before saving to the disk

At the moment, I am making use of the multer library to store files on the File system. This particular application is built using Node and Express. I currently have a process in place where I save the file on the server first and then encrypt it. After e ...