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

Centering a position absolute img with a position relative img

Hi!

I have 2 images, one with position absolute (the background) and one with position relative, I want to center the position relative one to the position absolute one. I tried a lot of methods, with margin auto, transform, and others but nothing works for me.

problem

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

Here’s my code (I’m using React.js):

import './information.css'

import Background from '../../assets/character_informations_bg.png'

export default function Information(props) {
  return (
    <div className="character-information">
        <div>
            <img src={Background} alt="" className='character-information-bg' />
            <img src={props.image} alt="" className='character-information-clothes' />
        </div>
        <p>{props.name}<br />{props.price}</p>
    </div>
  )
}

// CSS (information.css)
.character-information-bg {
    position: absolute;
}
.character-information-clothes {
    position: relative;
    max-width: 90px;
    max-height: 90px;
}

>Solution :

use left and top properties on .character-information-clothes

example –

.character-information-clothes {
  position: relative;
  left: 20%;
  top: 20rem;
  max-width: 90px;
  max-height: 90px;
}

adjust top and left according to yours background possitioning

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