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.

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

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

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

What is the optimal approach for moving the dashboard to a separate subdomain in a static Next.js-generated landing page?

Our current setup includes several static pages generated by Next.js using the command next build && next export These pages are hosted on AWS S3. I am wondering if we should create a new app for building a dashboard with Firebase authentication ...

Switch the background image of one div when hovering over a different div

Can anyone assist me with creating an interactive map where continents light up as you hover over them? I am using multiple images within div elements in order to achieve this effect. Specifically, I want to change the background image of one div when hove ...

"Discover the magic of creating a navigation menu with jQuery toggle - let me show

Recently, I managed to create a side navigation using the target function in CSS3. However, I am curious about how I can achieve the same result using jQuery without disrupting the layout. Any assistance would be greatly appreciated. Here is the code sni ...

designing items in various color palettes

section { background-color:#d5ecf2; width:1024px; height:200px; margin: 0 auto; } .sectiontext { float:right; height:180px; width:720px; margin:10px; } <section> <div class="sectiontext"> <h3>GDS 114.01: HTML and Javascript</h3 ...

Exploring the concept of clip-path

Recently, I have been delving into the world of HTML and CSS, exploring clip-paths after stumbling upon them on this captivating website. My interpretation is that utilizing clip-paths, particularly with the polygon attribute, enables one to control which ...

Setting a fixed row height for Material-UI tables in ReactJS, even when the content is long

I'm currently working on a listing component using the material UI table in ReactJS. Within this table, I have a ResumeUrl field that can span over 3 or 4 lines, but I need to limit it to just 2 lines with the rest of the content being represented by ...

JavaScript problem with hovering action causing additional buttons to appear

Currently, I am developing a user interface where, upon hovering over an LI element, 2 buttons appear to provide additional functionality - "edit" and "remove". However, I am facing challenges with the mouse hit zones. The mouseover function works effect ...

The issue of being unable to retrieve data from an API within a docker container from a React application is caused by the 'Access-Control-Allow-Origin'

I have successfully set up my Azure Functions API inside a docker container and can access it without any issues using Postman or Chrome. However, I am encountering an error when trying to access it from a React app. The error message states: from origin & ...

Tips for creating a hovering bar underneath your links

I'm currently working on designing a stylish navigation bar using CSS, and I have a specific feature in mind. When a user hovers over a link in the navigation bar, I want a colored bar to appear under a different link. Essentially, I need the backgrou ...

Enhancing forms using ReactJS and Redux

Here is the structure of my form: import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { updateExpert, fetchExpert } from "../../store/actions/expertActions"; class ExpertForm extends ...

There was an issue with the installation of "ethereumjs-abi" from the directory "node_modules/eth-sig-util/ethereumjs-abi@git+https:/github.com/ethereumjs/ethereumjs-

After accidentally deleting the .next and node_modules folder while experimenting, I attempted to run npm i, which resulted in the error message below: $ npm i npm ERR! code ENOLOCAL npm ERR! Could not install from "node_modules/eth-sig-util/ethereumj ...

How come my 'Select' components in react are automatically linked together?

I am currently facing an issue with my submission page using materialui. I have designed two 'Select' components on the page, but whenever I choose an option from the second component, it refreshes the option selected in the first component. Whil ...

Discovering the initial word of a string using jQuery

I'm currently facing an issue with jQuery that I need help solving. Here's the scenario: I am creating tooltips and positioning them directly under a specific trigger using CSS. Everything is functioning correctly, but there is one problem: In ...

Generating dynamic URLs with hyphens in Next.js - a step-by-step guide

Is it possible to create a unique dynamic path in Next.js, such as 'courses-demo-[dynamic_name]'? I have already set up nested folders in the following structure: courses-demo [...slug] index.ts However, this folder structure only allows path ...

The success message is not being displayed after clicking the pay button using ReactJS, Stripe Payments, Node, and

Currently, I am working with ReactJS, Node.js, and Express while integrating the Stripe Payment API. However, I am facing an issue where after clicking the pay button and entering the dummy credit card details, the payment processing does not proceed as ex ...

Tips for adjusting the size of icons in Ionic Framework v4 and Angular 7

The library ngx-skycons offers a variety of icons for use in projects. If you're interested, check out the demo here. I'm currently incorporating this icon library into an Ionic project that utilizes Angular. While the icons work perfectly, I&ap ...

The module 'crypto-js' or its corresponding type declarations cannot be located

I have a new project that involves generating and displaying "QR codes". In order to accomplish this, I needed to utilize a specific encoder function from the Crypto library. Crypto While attempting to use Crypto, I encountered the following error: Cannot ...

Enhance Angular Material UI accessibility and implement automatic value checking on load

I am facing an issue with an angular material drop down selector that offers multiple options, including a feature to select all options at once. https://i.stack.imgur.com/VyXxz.png I came across a code snippet on this website, which I found in r ...

Assign a CSS class to a DIV depending on the vertical position of the cursor

The website I am currently developing is located at Within the site, there is a collection of project titles. When hovering over a project title, the featured image is displayed directly below it. I would like to change the positioning of these images to ...

Disappearing act: The vanishing act of the Bootstrap 4 Smart Scroll Mobile

Utilizing the Smart Scroll feature from in Bootstrap has been successful on desktop, but issues arise on mobile devices. When scrolling down and returning to the top, the navbar experiences glitches by hiding again. Attempting solutions from Bootstrap 4 S ...