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

Develop a server-side component using Next.js that dynamically updates

I need to create a Next.js component that displays different greetings based on whether the current time's minutes are even or odd. The greeting should be "Hi" for even minutes and "Hello" for odd minutes, but this needs to be implemented in a server- ...

Is there a way for me to display text from server actions in Next.js?

Welcome to the world of Next.js import { PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); export default function Home() { const checkUser = async (formData: FormData) => { "use server"; const firstName = formData. ...

How can CSS and JavaScript be used to strategically position two upright images next to each other within a dynamically resizing container?

Looking for a way to display two portrait images side by side within a flexible container with 100% width? The challenge I'm facing is accommodating varying widths of the images while ensuring they are the same height. <div class="container"> ...

Testing React components with MUI5 Pro license key mocks in Jest: A step-by-step guide

As I integrate MUI v5 Pro components into my React library and import those components into my host app, I have configured the MUI license key in both the library and host app's .env files. The necessary components are being imported as follows: impor ...

Emphasize a specific line of text within a <div> with a highlighting effect

I'm looking to achieve a similar effect as demonstrated in this fiddle As per StackOverflow guidelines, I understand that when linking to jsfiddle.net, it's required to provide some code. Below is the main function from the mentioned link, but f ...

A demonstration of HighCharts integration within a React application

I'm currently utilizing React-js-highcharts and have encountered an error in the code below. I am receiving a message stating 'e.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other i ...

Ways to retrieve child state in React?

After creating my own form component with a render() method that looks like this: render() { return ( <form onSubmit={this.onSubmit} ref={(c)=>this._form=c}> {this.props.children} </form> ) } I enabled ...

Prevent the page from scrolling while the lightbox is open

I am struggling with a lightbox that contains a form. Everything is functioning properly, but I need to find a way to prevent the HTML page from scrolling when the lightbox is active. <a href = "javascript:void(0)" onclick=" document.getElementById(& ...

Tips for seamlessly incorporating React Epub Reader into your next js project

Having some trouble integrating the react epub reader with Next Js. It's working perfectly fine with react js, but I keep encountering an error. Can you help me figure out how to integrate the epub reader with next js? Here is the error This is my ...

Attempting to invoke setState on a Component before it has been mounted is not valid - tsx

I've searched through various threads regarding this issue, but none of them provided a solution that worked for me. Encountering the error: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a b ...

Adjusting the default TextField hint alignment - MaterialUI

As I delved into using material UI, I encountered a challenge with the TextField component. While the default animation was aesthetically pleasing, I desired to center align it instead of it remaining stuck in the top left corner: https://i.stack.imgur.co ...

Replacing the CSS Reset with the Universal Selector

I implemented Eric Meyer's Reset to set the font, and then loaded my stylesheet to globally set the font using the universal selector. Even though I loaded the universal selector in my SASS after the reset, the reset is still taking precedence. (Atta ...

The focus of Material v5 UI is on maintaining a clear and strict division of

In the past, I had centralized themes and styles in a file named themes.js while using v4 of Material UI. All styled components were placed under a single useStyles function. As I transition to Material v5, I want to continue centralizing everything while ...

Tips for making an input form that triggers an alert popup

After creating an HTML form with text input, utilizing Javascript for validation as shown below: I am trying to trigger an alert box thanking the user for entering data when the submit button is clicked. I have faced challenges in implementing this witho ...

Problem with CSS layout on Internet Explorer 9

I've encountered some layout difficulties in IE9 and I'm struggling to identify the root of the problem. Even though I'm using Foundation 5, I don't believe that's the issue. The content is within a Foundation grid set at large-12 ...

Adding a stylesheet dynamically in Angular 2: A step-by-step guide

Is there a method to dynamically add a stylesheet URL or <style></style> in Angular2? For instance, if the variable isModalOpened is set to true, I want to apply certain CSS styles to elements outside of my root component, such as the body or ...

A feature to reveal additional content when it extends beyond a single line

<div class="questionnaire-description col-xs-12" id="questionnaire_description_wrapper"> <text-truncate> <span ng-class="questionnaire_description.show_more ? 'full-description' : 'ph-ellips ...

Having Trouble with Font Awesome Icon Loading in Search Box

Currently, I am working on a website located at . However, I am facing an issue where the font awesome icon is not loading properly and is only displaying a square. I have thoroughly reviewed the CSS and cannot identify any conflicting elements. Any assis ...

How can I incorporate an onClick event into the HelperText of a Material UI TextField?

Can I trigger an onClick event on the helperText of a Material UI TextField? Additionally, is it possible to add two helperText elements to one TextField? <TextField variant="outlined" placeholder="Write a comment..." fullWidth ...

Ensuring continuous user login during webpage refreshes with the help of React and local storage

Currently, I am working on implementing the use of local storage to ensure that upon refresh, the user remains logged in rather than being signed out each time. Successfully, I have been able to store data in local storage by utilizing the following code ( ...