That solution requires some Javascript, which may not always be desirable. Also, please note that it uses .live(), which has been removed from jQuery starting with version 1.9. You should use .on() instead. Note that the parameters are different for .on() vs. .live().
CSS flexboxes are an alternative that are very handy for centering elements, laying-out elements to fit with even spacing, etc, if you can live with the limitation that they are only implemented in modern browsers. They are pretty universally supported, though, on mobile devices and modern desktop browsers.