在页面中水平居中DIV

时间:2013-06-08 06:30:02

标签: html5 html windows-8 microsoft-metro winjs

我正在尝试将一个div集中,这是用于HTML5 / JavaScript的Windows 8应用程序的Microsoft pubCenter AdControl。

    <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>

如何将div水平居中,使其始终位于页面中间?

5 个答案:

答案 0 :(得分:18)

margin:auto标记中添加style="",这应该可以解决问题。

其他可能性,align=center

答案 1 :(得分:7)

你只能使用css

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

要点是将边距设置为div宽度的一半

答案 2 :(得分:4)

你可以简单地将这个班级用于绝对中心

.ab_center
{
    height:300px;
    width:300px;
    background-color:#27f305;
    position:absolute;
    margin:auto;
    top:0;
    left:0;
    right:0;
    bottom:0;
}

示例小提琴:http://jsfiddle.net/devesh_dc/dzyvmt0o/

答案 3 :(得分:0)

在其他网站上找到HTML5,C#和VS2015。添加到css:#wrapper { width: 600px;margin: auto;}并用以下内容包装您的内容:
   <form id="form1"> <div id="wrapper"> Content </div> </form>

答案 4 :(得分:-6)

您可以在align='center'代码

中使用<div>