The hard comes in when you don’t know the dimensions of the element to be centered. View Demo