Spacing Issue with Material UI Gap Placement

Currently, I am implementing Material UI 5 within a React project using the following code snippet:

<Stack>
    <Stack
        flexDirection="row"
        justifyContent="center"
        padding={4}
        spacing={{ xs: 4 }}
    >
        <Box bgcolor={"red"} width={"200px"} height={"200px"}/>
        <Box bgcolor={"green"} width={"200px"} height={"200px"/>

        
    </Stack>
</Stack>

The issue with this code is that instead of having the specified margin between the boxes, there is an extra margin added to the top of the second box. It seems like the 'gap' property works fine, but the 'spacing' property does not behave as expected.

Expected Result: The correct way of applying spacing Actual Outcome: Incorrect margin added to the second box

I aimed to achieve equal spacing on the horizontal axis between the items.

Answer №1

To make the change, simply update the property flexDirection="row" to

direction="row"</cdoe>:</p>
<pre class="lang-js"><code>    <Stack>
      <Stack
        direction="row"
        justifyContent="center"
        padding={4}
        spacing={{ xs: 4 }}
      >
        {/* <MemoizedPlace {...place} key={place._id} /> */}
        <Box bgcolor={"red"} width={"200px"} height={"200px"}>
        <Box bgcolor={"green"} width={"200px"} height={"200px"}>
        {/* 
              <SideComments placeId={place._id} />
              <SideComments placeId={place._id} /> */}

        {/* <SideComments placeId={place._id} /> */}
      </Stack>
    </Stack>

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

Sending information (prop) from _app.js to getServerSideProps in a page on the most up-to-date version of NextJS

I have a unique custom _app.js that I created: const CustomLayout = ({ children }) => (children); const myApp = ({ Component, pageProps }) => { pageProps.url = 'another url'; return ( <CustomLayout> <Co ...

Changing colors using JavaScript: A step-by-step guide

Hey there! I'm looking to change the color code in this script from $("#Tcounter").css("color","black") which uses the color word "black", to "#317D29". Can someone help me figure out how to do this? <script type="text/javascript"> $(document). ...

What is the best way to transfer information from a server running Express.js to a client using React.js?

When using Express.js, I have the ability to send an HTML file that includes a React component. app.get('/index', function(req, res) { res.sendFile(path.join(__dirname + '/src/index.html')); }); Suppose I want to send a uniqu ...

Is it possible to run React and Express on a single server?

I am currently in the process of developing a React website that includes a contact page. Within this contact page, users can input a message that will be directed to a specific email address. At the moment, my focus is on integrating Express with my Reac ...

Tips for maintaining the chat scroll position while typing on mobile devices

Check out this example page: https://codesandbox.io/s/summer-flower-uxw47?file=/index.html:4175-4223 The issue at hand is that when accessing the site from a mobile device and tapping on the input field, the keyboard pops up. This causes the text in the m ...

Having trouble accessing properties that are undefined while using react JS, specifically when trying to read a 'map' property

Currently, I am in the process of building a blog with ReactJS and NextJS within VS Code. Despite not encountering any errors during coding, when I attempt to run it, the browser displays: "TypeError: Cannot read properties of undefined (reading 'map& ...

Conceal the navigation bar during the login process in a ReactJS application

Is there a more efficient method to hide the navigation while on the "/login" path? In my project, I implemented a react hook that toggles to true whenever the login component is rendered. <BrowserRouter> {!isLogin? <MainNav ...

The error in React syntax doesn't appear to be visible in CodePen

Currently, I am diving into the React Tutorial for creating a tic-tac-toe game. If you'd like to take a look at my code on Codepen, feel free to click here. Upon reviewing my code, I noticed a bug at line 21 where there is a missing comma after ' ...

Struggling to incorporate a Search Filter feature into my React project, unfortunately, it doesn't seem to be functioning correctly. Any assistance would be greatly appreciated. Can anyone lend

Hey there! I'm diving into the world of React and currently working on creating a search filter that fetches data from an API. Despite not encountering any errors in the console, it seems like my search bar isn't functioning properly. Any suggest ...

Issue with importing Node module (@pusher/push-notifications-web) occurring when page is refreshed in Next.js

Encountering a problem while trying to integrate the node module @pusher/push-notifications-web. More information can be found at https://github.com/pusher/push-notifications-web I'm unsure whether this issue is related to Next.js or the node module ...

Visualizing JSON data in React.js using Chart.js

Currently, as a beginner in ReactJS, I am working on an application that displays COVID-19 data from a JSON API in a visual format using Chart.js. However, despite trying various solutions, I am unable to visualize the data. Below is my source code: App ...

Clashing CSS Styles: Font Size Edition

Can someone explain how CSS font sizes work? I set a specific line to be 200% font size, but changing the body font size affected it. Shouldn't the line maintain its specified size? When the body font size is changed from 12pt to 8pt, the line "There ...

Tips for linking attributes to a function using ES6

I'm currently working on a stateless React.js component called myView. I want to keep the syntax as concise as possible, but I'm having trouble understanding how to export a default function with an attached object. Here's an example in myVi ...

What is the best way to insert a permanent script tag into the body of a Gatsby site? Can conditional rendering be used to control

As an illustration: - const nation = "USA" import chat from './utils/script'; // script is imported from a file if(nation === "USA") // utilized conditionally in the component { chat } else { console.log("Not USA") } inform me witho ...

Arranging DIV elements into rows and columns within a table

After working all night to fix a problem, my goal is to create this timetable: https://i.sstatic.net/dAt1J.png Specifically, I'm struggling to find a solution for rows 5, 6, and 7 in the first column. The image is from a program that only runs in IE ...

The specified 'Promise<Modules>' type argument cannot be assigned to the parameter of type '(params: any) => Promise<Modules>' in the current context

Looking for some help with this helper function that I need to call, it has the following signature: export const fetchPaginated = async <T>( callback: (params: any) => Promise<T>, { page = 1, pageSize, }: { page?: number; page ...

Is it possible to use CSS to create a gap between the cursor and the placeholder text within an input field?

Could you please assist me with a bug I have encountered on an older version of Firefox for OSX (37.0.2)? I have included a screenshot of the issue here: https://i.sstatic.net/dzK0G.png Is there a way to use css to move the first character of the placehol ...

Is the Express server double-posting, with a two-minute gap between each post?

I'm currently working on a project involving the development of a React chat box with an express server and pusher for dialogflow bot integration. Initially, everything seems to be running smoothly, but I'm encountering an issue where the bot res ...

Retrieve the value of the second child element in a table cell when clicking on it with Javascript

I have created a table with one row that includes the title of the month and a cell containing an inner table with multiple rows and cells. I want to display the content of the second cell in the second table as a modal box or alert dialog when it is click ...

What is the best way to create a smooth sliding effect using CSS?

Need help with creating a transition effect within a bordered div that reveals hidden content when a button is clicked? I'm looking to have the <a> tag displayed after clicking the button, with both the button and text sliding to the left. Here& ...