How to center a “position: absolute” element
If you have set a width you may use: position: absolute; margin-left: auto; margin-right: auto; left: 0; right: 0; text-align: center;
If you have set a width you may use: position: absolute; margin-left: auto; margin-right: auto; left: 0; right: 0; text-align: center;
This works for me: #content { position: absolute; left: 0; right: 0; margin-left: auto; margin-right: auto; width: 100px; /* Need a specific value to work */ } <body> <div> <div id=”content”> I’m the content </div> </div> </body>