h1 and h2 are block level elements so by default they are 100% wide. Instead of all of the complex calculation, simply use text-align: center;
h1
h2
text-align: center;
548k questions
547k answers
4 comments
86.3k users