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

278
Vistas
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 Respuestas
Responde la pregunta

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 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