Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
I can't get my image to fill the area of my grid

I have a 300x300 image that I'd like to fit into a grid (sized 158x175), but when I have...

<div className='box'>
   <div className='test'>
      <img src='https://via.placeholder.com/300x300' alt='Image Example'/>
   </div>
   <div className='test'>
      <p>Random text</p>
   </div>
   <div className='test'>
      <p>Random text</>
   </div>
</div>
box {
   display: grid;
   grid-template-columns: 158px auto auto;
   grid-template-rows: 175px;

   div.test {
      &:first-child {
         width: 100%;
         height: 100%;
         object-fit: cover;
      }
   }
}

like I've seen a lot of people say from doing some research, the 300x300 block shrinks to 158x158, leaving about 17px of grid space left below the image. I would like the image to be cropped to fit the entire space, but I can't seem to get it to work. Does anyone have ideas as to what I'm doing wrong? I have also tried replacing height: 100%; to height: auto, and that moves my image down a few pixels, but I pretty much have the same issue as before.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

couple of things!

  1. make sure that 'box' in your css is '.box'

  2. &:first-child

locks on to the occurrence of div.test, not div.test's first child.

So if you simply change your scss to be:

.box {
   display: grid;
   grid-template-columns: 158px auto auto;
   grid-template-rows: 175px;

   div.test {
      img {
         width: 100%;
         height: 100%;
         object-fit: cover;
      }
   }
}

Here is a codepen for you: https://codepen.io/webdevjones/pen/LYQPZaM

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda