Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
Resize image inside of a container to make it smaller if there is more text

So basically I want to resize my image depending on the available space of the container. I have a description and an image, and the image should resize depending on the amount of text in the description and not just push it upwards as it does for me now. In this project, I'm using react.

Default result if the description is small:enter image description here Unwanted result if the description is large:enter image description here Desired resault if the description is large:enter image description here

My current code:

<div className={classes["main-post-container"]}>
      <img className={classes["main-image"]} src={test} alt="test" />
      <p className={classes["main-description"]}>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Minus illo
        enim magnam neque fugit rem praesentium voluptate quod architecto aut
        non, id fugiat modi tempora hic sed amet, eligendi delectus. Lorem ipsum
        dolor sit, amet consectetur adipisicing elit. Temporibus obcaecati
        dolore mollitia animi praesentium laudantium sit cumque exercitationem.
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos minima
        pariatur quae id et officiis repellat doloribus, beatae ducimus quaerat
        repellendus nesciunt aliquid dolorem recusandae vero officia! Pariatur,
        voluptatem fugiat. .
      </p>
    </div>

CSS:

.main-post-container {
  width: 70%;
  height: 80%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  padding: 3rem;
}
.main-image {
  max-height: 450px;
  max-width: 800px;
  object-fit: fill;
  flex-grow: 1;
}
.main-description {
  font-weight: 900;
  font-size: 1rem;
  flex-grow: 3;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this css class:

.main-image {
  max-height: 450px;
  max-width: 800px;
  object-fit: fill;
  flex-grow: 1;
  height: auto
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!