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

177
Visualizações
Adjacent div's children needs to be level vertically

There are 3 Vertical divs, as shown in the picture. There are some child divs inside each div that are shown by blue rectangles. I need the children divs to be level vertically. How can I do it?enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As they said, in pure css/html is not possible if they are in separated containers. Using javascript you can first create the 'base' element (in this case, the inner divs of the center column), save its coord and then create the side ones and pos them with the saved coords.

This is a rough example, but can give the idea

for (let i = 1; i < 10; i++) {
  //Create the center column element first, from where to get the Y pos
  let elem2 = document.createElement('div');
  elem2.style.width = 'calc(100% - 10px)';
  elem2.style.height = '50px';
  elem2.style.margin = '5px';
  elem2.style.background = 'lightblue';
  document.querySelector('.col2').append(elem2);

  let coords = elem2.getBoundingClientRect(); //Getting coords data

  //creating first column elem
  let elem1 = document.createElement('div');
  elem1.style.position = 'absolute';
  elem1.style.top = coords.top + 'px'; //use de y pos from above
  elem1.style.width = 'calc(100% - 10px)';
  elem1.style.height = '25px';
  elem1.style.margin = '0 5px';
  elem1.style.background = 'pink';
  document.querySelector('.col1').append(elem1);

  //creating third column elem
  let elem3 = document.createElement('div');
  elem3.style.position = 'absolute';
  elem3.style.top = coords.top + 'px'; //use de y pos from above
  elem3.style.width = 'calc(100% - 10px)';
  elem3.style.height = '25px';
  elem3.style.margin = '0 5px';
  elem3.style.background = 'lightgreen';
  document.querySelector('.col3').append(elem3);
}
body,
html {
  margin: 0;
  padding: 0;
  background: lightyellow
}

.container {
  display: flex;
}

.col1 {
  position: relative;
  width: 75px;
  border: 2px solid red
}

.col2 {
  position: relative;
  flex-grow: 1;
  border: 2px solid blue
}

.col3 {
  position: relative;
  width: 150px;
  border: 2px solid green
}
<div class="container">
  <div class="col1">
  </div>

  <div class="col2">
  </div>

  <div class="col3">
  </div>

</div>

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