Unable to create a responsive layout because of the use of inline CSS with "margin"

Currently, I am working on a design for a webpage that must be responsive to large, medium, and small screens. To achieve this responsiveness, I am using Material UI Grid container and placing Chips inside it with the style={{ marginLeft: 60 }} from the second chip onward. However, when the screen size changes, these chips overlap each other without any responsive behavior. Below is the snippet of my code:

 <Grid container item xs={12}>
            <Grid container item xs={11}>
                <Grid item xs={2}>
                    <Chip/>
                </Grid>

                <Grid item xs={2} style={{ marginLeft: 60 }}>
                  <Chip/>
                </Grid>

                <Grid item xs={2} style={{ marginLeft: 60 }}>
                   <Chip/>
                </Grid>

                <Grid item xs={2} style={{ marginLeft: 60 }}>
                     <Chip/>
                </Grid>

                <Grid item xs={2} style={{ marginLeft: 57 }}>
                     <Chip/>
                </Grid>

            </Grid>
</Grid>

I am seeking advice on how to correct this design issue. Any suggestions would be greatly appreciated. Thank you in advance.

Answer №1

If you're looking to make your margin sizes flexible and responsive to different screen sizes, consider using relative values instead of static pixels. You can achieve this by adjusting the styling to something like style={{ marginLeft: '5%' }}, or by applying a className and implementing media queries in your CSS file to define breakpoints for specific screen sizes.

Opting for the latter approach will give you more control over the responsiveness of your design, which is particularly useful if adaptability across various devices is important.

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

What is the best way to align the Card Content with the MaterialUI Card Action button?

In my React application, I am incorporating Material UI Cards along with Bootstrap for div alignment. Below is the code snippet for the Card component: <Card elevation={10} className="mb-3"> <div className="row"> <d ...

Ways to display pictures by invoking an API within the antd item list container

Upon page load, I am fetching images from a database using an API. Now, my goal is to display these images within a Modal in Antd. How can I accomplish this with the code snippet below? const MyVehiclePage = (props) => { useEffect(() => { co ...

Display the background image beyond the boundaries of the div element

I am facing an issue with an image background on a website. The background consists of leaves spreading out to the middle of the page, creating a height of 600px. However, I need to divide this image into three sections: header, content, and footer. Curren ...

The background image on my website isn't showing up once it's been deployed via GitHub

I've tried various solutions to fix the issue at hand, but unfortunately, none of them seem to be effective. I double-checked the image path directory and confirmed that it is accurate. Even after uploading both png and jpg files, the problem persists ...

Attempting to load a URL from local files in the React Monaco Editor

In my react-electron typescript application, I am utilizing Monaco Editor with the @monaco-editor/react package. However, when I include the line import Editor from '@monaco-editor/react'; and then incorporate the Editor component into React, I ...

Error Type: nextjs 13 - children function TypeError

Welcome to the Home page: export default async function Home() { # console.log(data) it is populated const { data } = getAllArts(); return ( <main className="flex min-h-screen flex-col items-center justify-between p-24"> < ...

Encountering an error message saying "assignment to undeclared variable"

I'm attempting to incorporate a react icon picker from material-ui-icon-picker However, I keep encountering an error stating "assignment to undeclared variable showPickedIcon" edit( { attributes, className, focus, setAttributes, setFocus, setState ...

Solving the issue of IE7 div overflow-y: scroll causing content to be obscured by the scrollbar

I am facing an issue with a table inside a div (#body) that scrolls along the y-axis. Specifically, in Internet Explorer, the scrollbar is hiding part of the last table cell behind it, causing a shift in the layout of the table columns. This problem does n ...

The Next.js application is unable to load the combined CSS from a React Component Toolkit

My React components repository includes individual .css files for each component which are imported into the respective components. These components are then bundled using a rollup configuration and published as an NPM package, with all component CSS being ...

Problem with Material-UI Drawer

Is there a way to make this drawer stay fixed on the page like a sticker and remain active without moving when scrolling? I've tried using docked={false}, but it makes the whole page inactive except for the drawer. Any suggestions on how to solve this ...

The package is warning that it needs react version 16.4.0 or higher to be installed as a peer dependency, but

Upon trying to execute a project downloaded from github, I encountered some warnings while running npm install. One of the warnings displayed was: npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74150c011d59101500151306 ...

Error: 'window' object is undefined in the next application

Hey there! I'm facing an issue with my code in next.js. It's throwing an error that says "NextJS - ReferenceError: window is not defined". Can anyone guide me on how to troubleshoot and fix this? function WeatherIconComponent({icon}) { l ...

Acquiring the applicable CSS for a JavaFX 8 widget

While working on JavaFX styling with CSS, I encountered a challenge in understanding which CSS properties are directly affecting the appearance of a GUI widget. It reminded me of using Firefox web developer tools to inspect elements and view the specific s ...

The Mui dropdown menu does not automatically close when the cursor moves away

I have a menu that displays submenus when hovering over certain MenuItems. While onMouseOver is working correctly, the submenu does not close when I move the mouse away from the MenuItem. Below are my defined functions: const [anchorEl, setAnchorEl] = use ...

React's input onChange event does not trigger for the second time. It only works the first time

Recently, I developed a React JS application to import images from external sources and process them. To handle the user's onChange event, I utilized the onChange attribute to execute my handleChange function. However, I encountered an issue where it ...

Shrinking Ant Design Tree in Create React App

I'm wondering if there is a way to optimize and reduce the size of Antd when using it with React 16.13 (CRA). I came across a tutorial for "tree shaking" at https://www.npmjs.com/package/babel-plugin-import mentioned in the package.json file "plu ...

ReactJS - Switching to a digital time picker instead of an analog time picker

I'm currently utilizing the material-ui-datetimepicker library to showcase a calendar and time picker on my website. Here is how my analog time picker appears: Analog Time Picker However, I would like to switch it to digital mode, resembling this: ...

Selecting radio buttons across multiple div classes

I've been struggling to programmatically select specific radio buttons on a webpage. My goal is to automatically choose the second option in each group of radio buttons, but I'm getting lost in the syntax. Unlike most examples I've found on ...

Stop Antd Modal from automatically scrolling to the top

At the moment, I'm utilizing Ant Design (v4.22.8) and Next.js (v12.3.4) in my project. One issue I've encountered is with a Modal component that activates when a button is clicked. Instead of overlaying the current content on the screen, the moda ...

Guide on transferring data from a parent component to a child component and conducting field validation in React JS with Material UI

Currently, I am tackling validation in react js by utilizing material ui for validation purposes. I have a common component where all the validation logic resides. In this common component, I have set the state to capture all field values that I need in ...