Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

image and h4 elements are not coming side by side in React Material UI

i am uisng material ui in react. Trying to to put image and h4 adjecent. but they aligning vertically. i tried to adjust the width but not working.

enter image description here

import React, { Component } from "react";
import robo from "./robo.png";
import { makeStyles } from "@mui/styles";
const useStyles = makeStyles({
  logo: {
    width: 100,
  },
  name: {
    width: 100,
  },
});
const Home = () => {
  const classes = useStyles();

  return (
    <div>
      <img alt="Gyrodata" src={robo} className={classes.logo} />
      <h4 className={classes.name}>Maersk Invincible</h4>
    </div>
  );
};

export default Home;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

H4 is a block level element, that’s why it moved to the next line. You can use flex to make them inline or make h4 an inline element using display property.

In below code, I’ve used flex to make the children appear in the same row. You can find more information on flex here and its supported by all major browsers now.

Your updated code.

import React, { Component } from "react";
import robo from "./robo.png";
import { makeStyles } from "@mui/styles";
const useStyles = makeStyles({
  container: {
    display: 'flex',
  },
  logo: {
    width: 100,
  },
  name: {
    width: 100,
  },
});
const Home = () => {
  const classes = useStyles();

  return (
    <div className={classes.container}>
      <img alt="Gyrodata" src={robo} className={classes.logo} />
      <h4 className={classes.name}>Maersk Invincible</h4>
    </div>
  );
};

export default Home;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading