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

227
Vistas
What is the easiest and the fastest way to center a div?

Can anyone suggest me the fastest way to center a div in CSS ? Thank you !

<div class="wrap">
    <div class="container">
        <p>some content</p>
    </div>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Example 1: Center div using margin-auto

https://i8pn0.csb.app/margin-auto-example.html

<div class="container">
  <div class="child"></div>
</div>
.container {
  width: 350px;
  height: 200px;
  outline: dashed 1px black;
}

.child {
  width: 50px;
  height: 50px;
  background-color: red;
  /* Center horizontally*/
  margin: 0 auto;
}

Example 2: Center a Div Horizontally using display: flex

https://i8pn0.csb.app/flex-x.html

<div class="container">
  <div class="child"></div>
</div>
.container {
  margin: 25px;
  width: 350px;
  height: 200px;
  /* Center child horizontally*/
  display: flex;
  justify-content: center;
}

.child {
  width: 50px;
  height: 50px;
  background-color: red;
}

Example 3: Center a Div Vertically using display: flex

https://i8pn0.csb.app/flex-y.html

<div class="container">
  <div class="child"></div>
</div>
.container {
  margin: 25px;
  width: 350px;
  height: 200px;
  outline: dashed 1px black;
  /* Center vertically */
  display: flex;
  align-items: center;
}

.child {
  width: 50px;
  height: 50px;
  background-color: red;
}

These examples are not the only way but the easiest, and some of them only work on modern browsers.

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