Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontally center a DIV in page

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?

like image 318
ReignOfComputer Avatar asked Jun 08 '13 06:06

ReignOfComputer


2 Answers

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

Other possibility, align=center

like image 101
Dummy Code Avatar answered Oct 10 '22 20:10

Dummy Code


you can use css only

left:50%;margin-left:-146px;

the point is to set margin left as half of the div width

like image 43
sd1sd1 Avatar answered Oct 10 '22 21:10

sd1sd1