Positioning elements absolutely within a Material-UI Grid component

Is there a way to align a Material-UI icon with text so that the lowest point of the icon starts exactly at the baseline? We are using Material-UI Grid layout.

The issue we are facing is that if we align the icon using 'baseline', it appears too high. On the other hand, if we use alignSelf: 'center', it appears too low. At this stage, I am open to absolute positioning the icon to match the text baseline, but I am unsure if this can be achieved with flexbox.

  <Grid container justify="space-between" xs={6}>
    <Grid item>
      <Button variant="outlined">Cancel</Button>
    </Grid>
    <Grid item>
      <Grid container alignItems="baseline">
        <Grid item>
          <Grid container alignItems="baseline">
            <Grid item style={{ alignSelf: "center" }}>
              <Done />
            </Grid>
            <Grid item>
              <Typography>Done!</Typography>
            </Grid>
          </Grid>
        </Grid>
        <Grid item>
          <Button variant="outlined">Submit</Button>
        </Grid>
      </Grid>
    </Grid>
  </Grid>

In the current setup, the icon is rendering below the baseline while the text is correctly aligned: https://i.stack.imgur.com/I1iRi.png

https://codesandbox.io/s/elated-cerf-33mme?fontsize=14&hidenavigation=1&theme=dark

Answer №1

To adjust the position of the checkmark manually, you can customize the relative positioning like this:

   <Done style={{ position: "relative", top: "-1px"}} />

Modify the value of the top property to align the checkmark correctly. If you eliminate the alignSelf property, consider using top: "5px" as an alternative.

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

Unusual hue in the backdrop of a daisyui modal

https://i.stack.imgur.com/fLQdY.png I have tried various methods, but I am unable to get rid of the strange color in the background of the Modal. Just for reference, I am using Tailwind CSS with Daisy UI on Next.JS. <> <button className='btn ...

Safari causing placeholders to be sliced

I'm having trouble creating attractive placeholders in Safari. This is how it currently appears. Codepen: https://codepen.io/anon/pen/RLWrrK .form-control { height: 45px; padding: 15px; font-size: 16px; color: #8c8c8c; background-color: ...

How can I trigger the appearance of the navigation bar when reaching the second div while scrolling

Is there a way to make the navigation bar appear only when a user has scrolled down to the second div on the page? The first div is the header. I am wondering how this can be achieved using jQuery? <!DOCTYPE html> <html> <head> <me ...

I am looking to create a button with a transparent border within a white background container

I am trying to achieve a button border effect similar to the one in the image provided. I want to create a div with a white background color, and inside that div, I need to add a button with a 15px margin or padding while making it transparent. <div cl ...

Instructions on deactivating the background when the sidebar is displayed and closing the sidebar by clicking anywhere other than the sidebar

I'm in the process of creating a sidebar for my website. When the sidebar is displayed (by clicking showRight), I want to disable the background content so that the user can't interact with anything outside of the menu. If the user clicks on th ...

What causes the difference in behavior between Firefox and Chrome when it comes to multiple column rendering and the use of overflow

Recently, I came across an interesting issue in Firefox related to lists inside a div with columns:2 set. In Firefox, when overflow:hidden is applied to the list, it stops rendering in 2 columns. However, in Chrome, the list continues to render in 2 colum ...

What's the reason behind this file not opening?

When I try to insert this code into files index.html, style.css, and app.js, the page refuses to open. The browser constantly displays a message saying "The webpage was reloaded because a problem occurred." I am using a MacBook Air with macOS Big Sur and a ...

"Rearrange elements on a webpage using CSS and HTML to position one

Can we utilize CSS/HTML to visually move a full width element that is positioned below another one so that it appears above without altering the markup order? <div id="first">first</div> <div id="second">second</div> #first {…} ...

When Chrome DevTools are opened, some elements of a webpage undergo a transformation in their style

I've recently started working on a static webpage using VueJS/NuxtJS and Buefy as the UI library, although I am still learning about these technologies. One issue that I have encountered is that certain elements on the page change style when I open C ...

Is it better to import and use useState and useEffect, or is it acceptable to utilize React.useState and React.useEffect instead?

When I'm implementing hooks for state, effect, context, etc, this is my usual approach: import React, { useState, useEffect, useContext } from 'react'; However, I recently discovered that the following also works perfectly fine: import Re ...

a personalized material-ui autocomplete feature

I'm puzzled by the fact that autocomplete clears the selected value, while the logic for selecting a value works perfectly fine. Check out this sandbox example to see what I mean: sandbox example ...

Is it possible to modify the variables in a SCSS file within an Angular 2 project?

Currently, I am working with Angular 2 using a SCSS style. My challenge is to retrieve data from a server in order to change a specific variable within the component's style - specifically a percentage value. You can view the SCSS and HTML code here. ...

React - verifying properties

Here's a question that I've been pondering. In many situations, we find ourselves needing to check if props are undefined. But what about nested props? For example, let's say we have: this.props.data.income.data1.value.chartData and we wa ...

Issues with retrieving data from Firestore and storing it into an array in a React

Struggling to fetch data from my firestore and display it on the webpage. Despite trying all possible solutions and searching extensively, I am unable to get it working. When using the code below, nothing appears on the website. However, if I switch to th ...

Adjusting the font size of floating labels within Material UI version 5

Is there an easy way to adjust the font size of floating labels for input fields in React MUI v5? I remember researching this issue a year ago when we were using version 4, and at that time it was difficult to change the cover area calculation behind the l ...

Encountering a talebook mishap: the function fn.apply is not recognized

Currently, I'm in the process of refactoring a React webapp from CRA to utilizing Vite and encountering some hurdles with Storybook. The Storybook's interface opens up as expected, displaying a list of stories on the left panel. However, when sel ...

Captivating captions for captivating visuals. Pictures don't conform to a linear arrangement

As someone who is new to website creation, I am currently working on adding a CSS effect where a popup-text appears when an image is hovered over. I want to create a row of images for the popups by using an unordered list. However, I'm facing a proble ...

Enhancing Image Quality in Internet Explorer 10

Here is my current situation: I am working on a web page with a responsive design. The layout of the page consists of two vertical halves, and I intend to display an image (specifically a PDF page converted to PNG or JPG) on the right side. The challenge ...

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 t ...

Apply CSS styles to the checkbox

I am new to CSS and I need help styling a checkbox element. When the user selects one of the checkboxes, I want the background color to change to yellow. Thank you for any assistance you can provide! .radio_toggle { float:left; } .radio_toggle label ...