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

280
Visualizações
How to make a responsive rectangle grid with images inside

I am trying to make a rectangular grid on my portfolio website with images inside. The problem is that all of these images have different sizes, which makes it hard for me to create a good modular grid where the ratio stays the same.

Here is a picture of how it looks right now:

enter image description here

I want all of the images to look like the top right image within the grid, and when when the page is made smaller, is should keep the same ratio. I is fine by me to work with object-fit: cover, so parts of the image will be cut off.

Now my code looks like this (I wrote only copied the first two as example):

.grid:after {
  content: '';
  display: inline-block;
  /* clear: both; */
  column-count: 4;
  /* column-gap: 0; */
}

.element-item {
  position: relative;
  border: 1px solid black;
  width: 50%;
  height: auto;
  margin-left: -1px;
  margin-top: -1px;
  padding: 10px;
  background: white;
}

.element-item img {
  position: relative;
  width: 100%;
  height: 450px;
  object-fit: cover;
}


/* CHANGE IMG ON HOVER */

.switch {
  position: relative;
  display: inline-block;
}

.switch .img-top {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
}

.switch:hover .img-top {
  display: inline;
}
<div class="grid">


  <div id="techweek" class="element-item Coding Motion Poster">
    <div class="extra">coding</div>
    <div class="extra">poster</div>
    <div class="image">
      <a href="techweek.html">
        <div class="switch">
          <img src="img work/TechweekGif1.gif" alt="Glass Back" />
          <img src="img work/TechweekGif2.gif" class="img-top" alt="Glass Front" />
        </div>
      </a>
    </div>
    <div class="text">Type in Motion
      <p2>2020</p2>
    </div>
  </div>

  <div id="mytho" class="element-item Book" data-category="alkali">
    <div class="extra">book</div>
    <div class="image">
      <a href="mytho.html">
        <div class="switch">
          <img src="img work/Mytho1.1.jpg" alt="Glass Back" />
          <img src="img work/Mytho1.jpg" class="img-top" alt="Glass Front" />
        </div>
      </a>
      <div class="text">How It Really Happened
        <p2>2019</p2>
      </div>
    </div>
  </div>

</div>

about 4 years ago · Juan Pablo Isaza
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