Difference between transform: translate and position:relative;?

白昼怎懂夜的黑 提交于 2019-12-07 01:59:02

问题


As the title says, what are the differences between transform: translate(x, y) and position: relative.

Since they both accomplish the same thing (position elements) anyway, then how do they differ in purpose and application?

I read an article about centering elements using "transform: translate;" that said it is better to use "transform" due to GPU and optimization reason, but I don't really see the problem since it's not a big deal anyway if you're just re-positioning an element and not animating it.

So in the end, how are they both different and in what ways?


回答1:


Basically translate relies on CSS3 2D Transforms while the position property is a CSS2 level.

In browser that support it has been said that using translate will boost the entire graphical peformance of the browser,

but not all browser do support it,

so if you care to give widespread browser support CSS2 position is surely better,

while transform:translate() is the future.



来源:https://stackoverflow.com/questions/28091821/difference-between-transform-translate-and-positionrelative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!