Skip to main content

How to constrain images to certain aspect ratio

I am trying to figure out how to maintain a responsive and adaptive page while also keeping images a certain ratio, basically I have 3 divs with images layered over eachother, each one maintains their position relative to one another currently, however the images stretch and bulge with the page, which I am trying to avoid without setting pre-defined sizes.

Currently the code below is set up to maintain the sizing and spacing between each class and ID, I have tried using the attribute aspect-ratio but it doesn't seem to do anything, I am using a supported browser type and version.

HTML

<div className="middle">
                         <img src={mannequin} id='mannequin' className='img' alt="Jewelry"/>
                         <img src={chain}  id="chain" className='img' alt="chain"/>
                         <div className='anchors'>
                         {anchorsState.map((anchor, index) => {
                            return <img src={anchor} key={index} className={'anchor'+" "+"anchor"+index} alt="Jewelry" onClick={()=>{changeAnchor(index)}}/>
                        })}
                         </div>

CSS

.middle{
   position: absolute;
   height:75vh;
   width:60%; 
   box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.75);

}

.middle #chain{
    height:50%;
    width:80%;
    position:absolute;
    display: inline-block;
    left: 10%;
    bottom:25%;
    /* object-position: 50% 50%; */
}

.middle #mannequin{
    height:100%;
    width:100%;
    /* position:relative; */
}

.anchors{
      position:absolute;
      top:25%;
      height:100%;
      width:100%;
      flex-direction: column;
      justify-content: space-between;
}

.anchor{
   position:absolute;
   width:5%;
   height:5%;
   /* background-color: rgba(0,0,0,0.50); */
   border-radius: 50%;
   cursor: pointer;
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/uJIRwbH

Comments