transform and position:relative have the same effect.
The difference is that transform can simply act on the position:absolute element, while position:relative; requires additional html
From an animation perspective
There is a big difference when using transform or position to achieve animation effects.
When using transform, the GPU can be involved in the calculation, and the FPS of the animation will be higher.
When using position, the smallest unit of animation change is 1px, and when using transform to participate, it can be smaller (the animation effect is smoother)
Reference materials:
Why Moving Elements With Translate() Is Better Than Pos:abs Top/left
From a page layout perspective
transform
andposition:relative
have the same effect.The difference is that
transform
can simply act on theposition:absolute
element, whileposition:relative;
requires additional htmlFrom an animation perspective
There is a big difference when using
transform
orposition
to achieve animation effects.When using
transform
, the GPU can be involved in the calculation, and the FPS of the animation will be higher.When using
position
, the smallest unit of animation change is1px
, and when usingtransform
to participate, it can be smaller (the animation effect is smoother)Reference materials: Why Moving Elements With Translate() Is Better Than Pos:abs Top/left
by Paul IrishSummary
The functions are the same. But translate will not cause the browser to redraw or reflow, which is quite nice.