@huyphan2210
Posted
Hi, @vcalvo25
I saw your solution and I have some thoughts:
- I noticed you've used Flexbox on the
body
and appliedalign-items: center
, which is great! To fully center the card, you can simply addjustify-content: center
to thebody
and safely removemargin: 0
auto from the.container
. This way, the card will still be centered, and you're making better use of Flexbox for positioning. - As for when to use different units like
px
,em
,rem
,%
, andvw
/vh
:px
is an absolute unit, so it doesn’t change based on the environment.em
andrem
are relative units, whereem
is based on the parent’s font size, andrem
is based on the roothtml
font size. If you don't change thefont-size
of thehtml
, thenrem
can be considered as a fixed unit, with1rem
equal to16px
by default.%
is relative to the size of the parent element, andvw
/vh
are based on the viewport width and height.
Examples:
px
:font-size: 14px;
(fixed size, doesn’t adapt to screen size)em
:font-size: 2em;
(twice the size of the parent’s font size)rem
:font-size: 1.5rem;
(1.5 times the root font size, i.e.,24px
if the root font size is16px
)%
:width: 50%;
(half the width of the parent element)vw
/vh
:width: 80vw;
(80% of the viewport width)
I'd personally use px
or rem
(if I don’t change the html
font-size
) for elements that rarely need to change size, and I’d use the other units for responsive purposes.
Hope this helps!