How can I utilize Material-UI's Grid component to make a single cell occupy the entire remaining horizontal space?

I am currently utilizing the Grid component from material-ui in my React 16.13.0 application. My objective is to create a row with three items. The first two items are supposed to occupy only the required space without specifying pixel values. I want the third item to take up the remaining horizontal space and align to the right (since using "float: right" seems problematic in React). Here's what I have so far:

const styles = theme => ({
  root: {
    textAlign: "left",
    margin: theme.spacing(2),
    paddingBottom: theme.spacing(1),
    color: theme.color.secondary,
  },
  cardHeader: {
    paddingBottom: theme.spacing(0),
  },
  cardContent: {
    width: "100%",
    paddingBottom: theme.spacing(1),
  },
  rowBody: {
    width: "100%",
    flexWrap: "nowrap",
    alignItems: "center",
  },
});
...
      <CardContent className={classes.cardContent}>
        <Grid container className={classes.rowBody}>
          <Grid item>
            <img height="20" src={require('../../img/apple.svg')} alt="" />
          </Grid>
          <Grid item>
            {title}
          </Grid>
          <Grid item>
            <InfoIcon />
          </Grid>
        </Grid>

Unfortunately, this arrangement results in everything being clustered together.

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

How can I modify the styles to achieve my desired layout?

Edit: This is how it appears following the suggestion provided by @Mohsen007 ...

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

Answer №1

Check out the following code snippet:

rowBody: {
    width: "100%",
    flexWrap: "nowrap",
    alignItems: "center",
    display: "flex",
},

<Grid container className={classes.rowBody}>
     <Grid item>
         <img height="20" src={require('../../img/apple.svg')} alt="" />
     </Grid>
     <Grid item style={{flex: 1,}}>
         {title}
     </Grid>
     <Grid item>
         <InfoIcon />
     </Grid>
</Grid>

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

Encountering a Basic React Issue: Unable to Implement @material-ui/picker in Next.js

I'm currently attempting to integrate the @material-ui/pickers library into my Next.js application. In order to incorporate the Picker provider, I followed the guidance provided in the Next.js documentation by adding the _app.js file inside /pages: i ...

I am unable to utilize the Web Share API for sharing a file within my React app written in TypeScript

Trying to launch a WebApp for sharing files has been quite a challenge. After some thorough research, I stumbled upon the Web Share API which seemed like the perfect solution based on standard practices. The documentation provided a clear outline of how it ...

Ways to troubleshoot CORS issue while working with pseudo API?

While utilizing a mock API, I encountered the familiar error message: "No 'Access-Control-Allow-Origin' header is present on the requested resource.". Despite watching videos and reading articles on this issue, the solutions provided we ...

Using props to pass objects into a React Link in a seamless manner

I'm currently attempting to pass a property from one component down to another using Link from 'react-router-dom'. The property I want to pass down is {this.props.postContent}. <Link to={{ pathname: "/posts/" + this.props.postConten ...

Incorporating @font-face webfonts into a Jekyll project

I'm currently working on incorporating webfonts into a Jekyll build. Interestingly enough, the fonts show up perfectly fine when I view them locally, but once I push my project to a live environment, the fonts mysteriously disappear. To make matters w ...

Get hands-on experience with API Gateway Tutorial by running it on

After successfully deploying the app from the tutorial found here: https://github.com/awslabs/aws-api-gateway-developer-portal, I am now looking to heavily customize the client or create a new one. Can development be done locally and then connected to AW ...

Passing a deconstructed object as a parameter for a function

I'm having trouble understanding the parameter const Posts in the code snippet below. As a newcomer to node/React, I'm not sure if it's a destructured parameter object or just an object being passed as a parameter. The functions getPosts an ...

Generating drop-down menus using React based on an array

After creating a custom navbar, I encountered an issue with populating the sub-menu for each county with its corresponding towns. The data structure involves counties with a parent ID of '1' and towns with parent IDs ranging from 2 to 22. Bleking ...

What is the best way to modify just a portion of the state in React?

Consider the following State object: const initialState = { data: { user: '', token: '', } } In the Reducer function: case 'DO_SOMETHING': return {...state, data: action.payload } If I make a shallow copy of th ...

Utilizing SVG and CSS together: Implementing clip-path in a flexbox layout

This task may seem simple to some, but I am struggling to mask an image with an SVG graphic. I have created an SVG with the clipPath element: <svg id="heart-path-container" version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 ...

A total of 63 security weaknesses were discovered while developing a new React

Hey there! I'm venturing into the world of creating a react app, but it seems like I've encountered 63 vulnerabilities. As a new user of React, I would greatly appreciate any experienced individuals who can assist me in setting up my project. Tha ...

Elements within the DIV tag are not displaying in a linear arrangement as intended

I'm having trouble creating a navbar with Bootstrap 4. The items in my div tag are not inline, and I can't align my nav item to the right. Here is the HTML code: <nav class="navbar navbar-inverse "> <div style="display:inline"> ...

The module 'react-bootstrap' does not have a 'Label' export available

Attempting npm start resulted in the following error message. ./src/App.js 104:16-24 'react-bootstrap' does not contain an export named 'Label'. How can this issue be resolved? I attempted to use npm install. Is there an alternative co ...

React: "The function is not toISOString"

I am currently working on a Todo List project using Next.js. As part of the functionality, I am trying to implement a due date feature. However, when I make a post request, I encounter the following error: Unhandled Runtime Error TypeError: dueDate.toISOSt ...

React JS BlueprintJS Date Range Picker not functioning as expected

I am struggling to implement a DateRangePicker using BlueprintJS on my component, following the instructions in the documentation. I also want to include a RangePicker similar to the one shown in this screenshot. I have successfully installed all the nece ...

The CSS transition for a DIV on an iOS Safari browser is experiencing a lag

In an attempt to optimize CSS transitions in the IOS Safari browser, I decided to use the transform: translate() property instead of changing the left property like other suggestions. Unfortunately, this approach did not yield the expected results as the ...

How can the data label name be displayed on the y-axis using recharts?

Issue: I've utilized recharts to create vertical bar charts, and here is the code I am using. import React, { Component, PureComponent } from "react"; import { Card, CardBody, CardTitle } from "reactstrap"; import { Bar, BarChart, Tooltip, ...

Is it possible to update a MobX state when a message is received from Firebase in the background?

I've set up Firebase in my project like this: import { initializeApp } from 'firebase/app'; import { getMessaging, getToken, onMessage, isSupported } from 'firebase/messaging'; import store from './flag'; ...

The declaration file for the 'react' module could not be located

I was exploring Microsoft's guide on TypeScript combined with React and Redux. After executing the command: npm install -S redux react-redux @types/react-redux I encountered an error when running npm run start: Type error: Could not find a decla ...

Preventing navigation without using the <Prompt> component in React Router DOM V6

I have recently discovered that in react-router-dom v5, it was possible to utilize the <Prompt> component to prompt the user before a page transition occurs, allowing them to prevent it. However, this feature has been removed in v6 with plans for a m ...