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

277
Visualizações
How do you vertically align parent elements based on active child elements?

Simply: If you have a parent div that contains a vertical list from 0 to 9, how do you vertically center the div precisely on the active child element?

This image will help visualize

I essentially have my HTML as:

<div className={`column currentValue${props.integer[0]}`}>
     <div className="number columnValue_0">
          0
     </div>
     <div className="number columnValue_1">
          1
     </div>
     <div className="number columnValue_2">
          2
     </div>
     <div className="number columnValue_3">
          3
     </div>
     <div className="number columnValue_4">
          4
     </div>
     <div className="number columnValue_5">
          5
     </div>
     <div className="number columnValue_6">
          6
     </div>
     <div className="number columnValue_7">
          7
     </div>
     <div className="number columnValue_8">
          8
     </div>
     <div className="number columnValue_9">
          9
     </div>
</div>

and based on the number being passed, the CSS is this:

.currentValue0 {
  margin-top: 24.4em;
}
.currentValue1 {
  margin-top: 21em;
}
.currentValue2 {
  margin-top: 20.1em;
}
.currentValue3 {
  margin-top: 19em;
}
.currentValue4 {
  margin-top: 15.9em;
}
.currentValue5 {
  margin-top: 17em;
}
.currentValue6 {
  margin-top: 11.6em;
}
.currentValue7 {
  margin-top: 9.5em;
}
.currentValue8 {
  margin-top: 7.4em;
}
.currentValue9 {
  margin-top: 5.2em;
}

I used flexboxes where needed to center everything but the main concern was trying to achieve this. Using 'em' to vertically align each column dynamically isn't giving accurate results on other devices beyond my pc monitor.

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

0

A crazy idea using inline-block and float. The trick is to make your list inline-block having float element inside. Relying on the default baseline alignment we simply make the active element non-float so it will define the baseline of its parent element:

.container {
  border:2px solid;
  padding:50px;
  text-align:center;
  background:linear-gradient(red 0 0) 0 47%/100% 1px no-repeat; /* to illustrate the basline */
}

.container .list {
  display:inline-block;
  border:1px solid;
  margin:0 10px;
  padding:2px
}
.container .list * {
  float:left;
  clear:left;
}
.container .list .active {
  float:none;
}
<div class="container">
  <div class="list">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div class="active">6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
  </div>
  <div class="list">
    <div>1</div>
    <div class="active">2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
  </div>
  <div class="list">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div class="active">4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
  </div>
  <div class="list">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div class="active">7</div>
    <div>8</div>
    <div>9</div>
  </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