What is difference between
position: absolute;
top: 50%;
left: 50%;
and
transform: translate(-50%, -50%);
?
What is better to use?
What is difference between
position: absolute;
top: 50%;
left: 50%;
and
transform: translate(-50%, -50%);
?
What is better to use?
position: absolute;
top: 50%;
left: 50%;
This object is placed according to the parent
element. It will change according the parent
's position.
transform: translate(-50%, -50%);
This object is based on itself. If the object is moved, it will translate according its new position.
Although both can show the same result in initial format, you will notice clear differences when styling parent
elements.