Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

279
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda