Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created November 2, 2020 23:31
Show Gist options
  • Select an option

  • Save teffcode/c53c36ee3e04efdcb3a11b70d56f4f8d to your computer and use it in GitHub Desktop.

Select an option

Save teffcode/c53c36ee3e04efdcb3a11b70d56f4f8d to your computer and use it in GitHub Desktop.

馃憢馃徏 Welcome 馃憢馃徏

Quiz banner

Instagram | Twitter | LinkedIn


Choose your language 馃憛



English version 馃殌


How can the container element center an element with only 2 lines of code ?


Click here to see the correct answer and explanation 馃憖
Correct Answer Explanation
C place-items is a shorthand to set both align-items and justify-items at once. By setting it to center, both align-items and justify-items are set to center.

Explanation based on 馃憠馃徏 Ten modern layouts in one line of CSS | Web Dev

Code:

HTML:

<div class="container">
   <div class="item"></div>
</div>

CSS:

.container {
  background: mistyrose;
  display: grid;
  height: 100px;
  place-items: center;
  width: 100px;
}

.item {
  background: hotpink;
  border-radius: 50%;
  height: 40px;
  width: 40px;
}


Spanish version 馃殌


驴El elemento contenedor c贸mo puede centrar un elemento con s贸lo 2 l铆neas de c贸digo?


Haz click aqu铆 para ver la respuesta correcta y su explicaci贸n 馃憖
Respuesta correcta Explicaci贸n
C place-items es una forma abreviada de configurar align-items y justify-items a la vez. Al establecer place-items en center, align-items y justify-items tambi茅n se establecen en center.

Explicaci贸n basada en 馃憠馃徏 Ten modern layouts in one line of CSS | Web Dev

C贸digo completo:

HTML:

<div class="container">
   <div class="item"></div>
</div>

CSS:

.container {
  background: mistyrose;
  display: grid;
  height: 100px;
  place-items: center;
  width: 100px;
}

.item {
  background: hotpink;
  border-radius: 50%;
  height: 40px;
  width: 40px;
}


@joshuacba08
Copy link

Muy bueno! Muchas gracias por tu aporte. Lo tendr茅 en cuenta 馃槉

@cquiladiaz
Copy link

C. Justify+align = Place , de esa manera hacemos las dos intrusiones en una sola linea 馃挌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment