Horizontally center a DIV in page

ReignOfComputer picture ReignOfComputer · Jun 8, 2013 · Viewed 67.6k times · Source

I'm trying to center a div, which is the Microsoft pubCenter AdControl for Windows 8 apps in HTML5/JavaScript.

    <div id="myAd" style="; top: 0%; width: 292px; height: 60px; z-index: 1"
        data-win-control="MicrosoftNSJS.Advertising.AdControl"
        data-win-options="{applicationId: 'exampleAdId', adUnitId: 'exampleAdUnit'}">
    </div>

How would I center a div horizontally so it is always in the middle of a page?

Answer

Dummy Code picture Dummy Code · Jun 8, 2013

Add margin:auto in your style="" tag and that should do the trick.

Other possibility, align=center