Instagram | Twitter | LinkedIn
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;
}
驴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;
}

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