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

286
Views
Fill a div with repeated images without cutting the last image

I have been trying to repeat images without cutting the last images, i have tried the ordinary background-image style to repeat the image but u can't always get the perfect results. I have set the background image in a position absolute span inside li the span has 86% of the li so i can see a little of the last letter.

background-image: url(https://source.unsplash.com/jTSf1xnsoCs);
background-size: auto 51px;

In the first example the images fit the 86% of the li cause there is enough space, but in the second one the image is cutted. as i said i have used the background-image style.

enter image description here

Is there a way to fit the 86% or even 100% of li with completed images using javascript

Here is an example https://jsfiddle.net/4cfjd10a/

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Does background-repeat: space along with background-size: contain accomplish what you're after?

From the MDN background-repeat docs:

The image is repeated as much as possible without clipping. The first and last images are pinned to either side of the element, and whitespace is distributed evenly between the images. The background-position property is ignored unless only one image can be displayed without clipping. The only case where clipping happens using space is when there isn't enough room to display one image.

This example is copied from your fiddle. I've removed the spans and corresponding css, and added the li a css rule:

ul {
  padding-left: 0;
  list-style: none;
  font-size: 40px;
  line-height: 51px;
  font-weight:bold
}
ul li {
  margin-bottom: 20px;
}
ul li a {
    position: relative;
    display: table-caption;
    
}
li a {
  background-image: url(https://source.unsplash.com/jTSf1xnsoCs);
  background-repeat: space;
  background-size: contain;
}
<ul>
  <li>
    <a href="#">
      Specialized
    </a>
  </li>
  <li>
    <a href="#">
      Optimized
    </a>
  </li>
</ul>

about 4 years ago · Juan Pablo Isaza Report

0

I can see solutions to your issue that do not require JavaScript but it would depend on what "perfect" means to you. There are 2 possibilities that I can see to solving your problem:

1. The repeated images are the same length Background Repeat Same Length Image

Then simply by setting your ul li span width to 170px instead of 86%. Seeing that your elements are not responsive to resizing, using a solid value for width should work in the styling.

2. The repeated images need to span different lengths Background Repeat Different Length Image For this, simply have a class added to your span for whichever width is not default and set the width accordingly.

<ul>
  <li>
    <a href="#">
      Specialized
      <span class="specialized"></span>
    </a>
  </li>
  <li>
    <a href="#">
      Optimized
      <span></span>
    </a>
  </li>
</ul>

.specialized {
  width: 204px;
}
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!