I recently refactored some of my CSS and was pleasantly surprised to find an easier way to horizontally align my absolutely positioned element:
.prompt-panel {
left: 50%;
transform: translateX(-50%);
}
This works great! Even if my element's width is auto. However, I do not understand what's going on to make this actually work. My assumption was that translateX was just a modern, more performant means of moving an element around, but that does not appear to be the case.
Shouldn't these two values cancel each other out? Furthermore, why does
.prompt-panel {
left: -50%;
transform: translateX(50%);
}
not show the same result as the first code snippet?