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

152
Views
Proportionally resize dynamic LIST of images based on amount of images in list

I have a couple of dynamically added containers to another container (let's call those items Loading solutions). Inside every Loading Solution, I would like to add as many truck icons as the Loading Solution has in its configuration.

So, for example:

  • solution 1 has only 1 loading, so it should only display 1 truck.
  • solution 2 has 5 loadings and should display 5 trucks.
  • solution 3 has 20 loadings and should display 20 trucks.

Now the problem is that eventually, all those truck icons do not fit in the container anymore.

How could I automatically resize the images inside every Loading Solution container while still generating them dynamically?

This is what it looks like right now: enter image description here

But this is what I want to achieve: enter image description here

Edit: This is my Vue template for the truck icons

<div class="trucks">
    <div class="truck-img d-inline-block mr-4" v-for="i in item.loads" :key="`load-${i}`">
        <img src="@/__app_assets/img/truck.png" alt="truck" />
    </div>
</div>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Pure HTML and CSS solution:

.container {
  background: gray;
  width: 300px;
  height: 200px;
  display: flex;
  align-items: center;
}

.inside {
  display: flex;
  flex-flow: wrap;
}

.item {
  margin: 4px;
  flex: 1 0 16%;
}

.item:nth-child(n + 6){
  max-width: 52px;
}

img {
  max-width: 100%;
}
<div class="container">
  <div class="inside">
    <div class="item">
      <img src="https://i.imgur.com/Jf1Pzoo.jpg"/>
    </div>
    <div class="item">
      <img src="https://i.imgur.com/Jf1Pzoo.jpg"/>
    </div>
    <div class="item">
      <img src="https://i.imgur.com/Jf1Pzoo.jpg"/>
    </div>
  </div>
</div>

If you want to change the number of max columns per row (the actual is 5), adjust the flex-basis percentage of the item class, the max-width of the nth-child and its argument (n + (cols + 1)).

over 4 years ago · Santiago Trujillo 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!