Difference between transform:translate3d(50%,0,0) and left:50% in css?

烈酒焚心 提交于 2019-12-23 15:17:20

问题


How does the transform:translate3d(50%,0,0) differ from left:50% in css? heres the jsfiddle that i made.

transform: translate3d(50%,0,0)

and

left:50%;


回答1:


translate3d(50%,0,0) considers the percentage as of the element itself, so it is being translated from the left half of the element size.

The left of the div that is positioned absolute in the fiddle is relative to the container div which is positioned relative, so the left:50%;is 50% of this container.




回答2:


Left value describes width related to parent element(or what it would be if width :100% was set)
transform values describe in relation to its own width

Since you have explicitly set a width, the 2 results are different



来源:https://stackoverflow.com/questions/38842981/difference-between-transformtranslate3d50-0-0-and-left50-in-css

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