The Material UI Grid item shifted upwards as a result of the image loading

While working on a project using the Material UI grid system with create-react-app, I encountered an issue with two adjacent grid items. Initially, they display as intended:

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

However, upon loading the page, there is a brief moment where the text on the right side shifts upward and appears unstyled:

https://i.sstatic.net/VOKZ4.pngI believe this behavior occurs because the image hasn't fully loaded yet, causing the text to move up temporarily. Any suggestions on how to prevent this flash of unstyled content would be greatly appreciated!

For reference, here is a code sandbox to recreate the issue. When navigating from the home page to /portfolio while in full screen mode, you will see the flash of unstyled content that I am describing.


<Grid container justify='center' alignItems='center'>
  <Grid item xs={12} sm={9} md={9} lg={6} xl={6}>
    <img src={JobTracker} alt='jobtracker' style={{ width: '100%' }} />
  </Grid>

  <Grid item xs={12} sm={9} md={9} lg={6} xl={6}>
    <Container maxWidth='xs'>
      <Typography variant='h3' style={{ textAlign: 'center' }}>
        JobTracker
      </Typography>
      <br />
      <Typography variant='body2'>
        A platform that allows recent graduates from Wyncode Academy to track job applications. Technologies used: ReactJS, NodeJS, Google Cloud Functions, and Google Firestore.
      </Typography>
    </Container>
  </Grid>
</Grid>

Answer №1

In my personal experience, I have found that wrapping images in a container with a fixed ratio, such as the golden ratio in my case, helps prevent issues like the one you mentioned. This is because when an image has not loaded yet, the container (in this case, the Grid component) has no height.

By utilizing a fixed ratio wrapper, you ensure that the image always has a designated height within its wrapper. It's as simple as that. For more information on this technique, you can check out this link: https://css-tricks.com/aspect-ratio-boxes/

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

Integrating the Avatar object into MUI card components

Can you help me figure out how to utilize an Avatar object in a Card mui? Here is the current code snippet I have: mycard = () => ( <Card> <CardHeader title="RamPriya" avatar="https://scontent.fmaa3-1......" /> </ ...

Guide to creating adaptive content using React and Material UI

For my current project, I am working on designing a product detail page using React and Material UI. The challenge I am facing is ensuring that the page remains responsive across different screen sizes. Specifically, I am struggling with the description se ...

What is the best way to adjust the height of a Div to be 100%?

I've been struggling to make the .footer and the div .content have a height of 100%. While I know how to get the footer to stick at the bottom, I can't seem to make the content div reach the bottom of the page. Increasing the min-height on the co ...

Working with React Hooks: Implementing a POST request to a server

I am new to React.js and I need help with sending a POST request from a form to a database. I believe I may need to include <form action="URL"> in my implementation. Any assistance would be greatly appreciated. Below is the code snippet fro ...

Clear out the classes of the other children within the identical parent division

I'm currently in the process of replacing my radio circles with div elements. I've successfully implemented the functionality for selecting options by clicking on the divs, as well as highlighting the selected div. However, I'm facing trou ...

Setting a future date and time in Material-UI using the <textfield type="datetime-local" /> pattern

Is there a way to automatically set the default time of an event to be 4 hours later than the current time? For example, if it is October 31, 2021 at 3:00 am, the default time should display as October 31, 2021 at 7:00 am. Or if it is October 31, 2021 at 1 ...

How to automatically disable a button in reactjs when the input field is blank

I have a component called Dynamic Form that includes input fields. The challenge I am facing is how to disable the submit button when these input fields are empty, although the validateResult function fails to return false. import cn from "classname ...

Error message: The export 'LocalizationProvider' (imported as 'LocalizationProvider') cannot be located in '@mui/lab/LocalizationProvider' while using React js Material UI

Just starting out with React Js Material Ui and using the latest version of MUI. I've installed mui/lab, but when attempting to utilize the DatePicker component, I'm encountering an error. Below is my code snippet: import * as React from 'r ...

The API results are able to be displayed in the console, but unfortunately cannot be shown on the user interface. Any efforts to map the results will result in an Un

Can anyone help me troubleshoot an issue with displaying information from a free API on my page? I'm developing a cryptocurrency app using React, and while I can see the array data with console.log(response.data), I encounter an error when I try to se ...

Sorting an array of Material-UI's <TableRow> alphabetically using ReactJS and Material-UI. How to do it!

I am currently utilizing Material-UI's <Table> and <TableRow> components by rendering an array of <TableRow>s using the .map() method. Each <TableRow> contains a <TableRowColumn> representing a first name, for example: &l ...

The absence of a rendered annotation line is noticeable on the Line Chart

I seem to be having trouble getting a horizontal line to show above the LineChart. Can anyone spot where I might be going wrong? I am using the following libraries and bundler: "chart.js": "^3.3.0", "chartjs-plugin-annotation" ...

Guide on setting component state according to rows selected in Material UI table

Seeking guidance to assist a learner with this task. The Project at Hand I am working on creating a form with 2 inputs: A text field for patient email An array generated by selecting table rows My goal is to update the component state with the values ...

Reduce the use of if statements

Is there a way to optimize this function by reducing the number of if statements? The currentFeatures are determined by a slider in another file. The cost is updated if the currentFeatures do not match the previousFeatures, and if the user changes it back ...

Tips on implementing loops in promises

Struggling to execute a for loop within a promise, I suspect the issue lies in where to call resolve but unsure. /* * Retrieve user conversations * @param user {String} */ function getConversations(user){ return new Promise(function(resolve, reject){ va ...

How can I switch to another screen from the menu located within my Parent Component?

I've been working on adding a customized navigation menu to my react-native app, but I'm currently facing the challenge of not being able to navigate to the corresponding screens of the selected menu items. I tried using this.props.navigation.nav ...

CSS/SCSS/JS: Adjusting header height dynamically while keeping it fixed at the

Check out my Codepen demo here: https://codepen.io/nickfindley/pen/dJqMQW I am seeking to replicate the current behavior of the page without specifying a fixed height for the header. The goal is to make the header adjust dynamically based on the content, ...

Issue with fullPage.js - Unable to scroll to footer on the last section of the page

I'm currently working with the fullPage.js plugin () and encountering some issues. While sliding through each section, everything functions as expected. However, when I reach the last section and try to scroll down to the footer below it, I encounter ...

Printing Apex Oracle reports using Internet Explorer

I am facing a challenge with printing my page that contains two interactive reports. To enable printing, I have utilized a JavaScript function that triggers window.print(). I have incorporated CSS to adjust the layout of my tables when printed. @media pr ...

Using CSS to Create Text Wrapping

I have a massive string of randomly generated numbers that I am trying to display in a div block. Since the string is quite long, it's currently being shown in one single line. For instance: String str="13,7,5,1,10,7,18,11,17,10,9,16,17,9,6,19,6,13, ...

Is it worth the effort to assign propTypes for mandatory properties repeatedly throughout nested components?

When one component always calls another, but adds some properties, do you use PropTypes for required properties in the calling component even if they are checked in the component being called? Or only at the higher level? To illustrate: const Input = pro ...