@huyphan2210
Posted
Hi, @ChristinePena
Regarding your question about centering a component, there are a couple of alternative approaches you could try, though they aren't necessarily better:
- You can use CSS Grid instead of Flexbox on the body, dividing it into two rows. The first element will be centered, and the second one placed at the bottom:
body {
display: grid;
grid-template-rows: 1fr auto;
place-items: center;
}
- Another option is to set
position: relative
on the body andposition: absolute
on themain
tag while placing thefooter
at the bottom. Usetop
,left
, andtransform
to center themain
:
body {
position: relative;
}
main {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
}
Hope this helps!