【问题标题】:Horizontally center a DIV in page在页面中水平居中 DIV
【发布时间】:2013-06-04 12:12:40
【问题描述】:

我正在尝试使一个 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 水平居中,使其始终位于页面中间?

【问题讨论】:

标签: html windows-8 microsoft-metro winjs


【解决方案1】:

你只能使用 css

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

重点是将margin left设置为div宽度的一半

【讨论】:

  • 或者使用margin:0 auto...更简单。
【解决方案2】:

在您的 style="" 标签中添加 margin:auto 就可以了。

其他可能性,align=center

【讨论】:

    【解决方案3】:

    你可以在&lt;div&gt;标签中使用align='center'

    【讨论】:

    • html5不支持这个
    【解决方案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/

    【讨论】:

      【解决方案5】:

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

      包装您的内容

      【讨论】:

        猜你喜欢
        • 2015-12-16
        • 2021-03-10
        • 1970-01-01
        • 1970-01-01
        • 2013-03-30
        • 1970-01-01
        • 2017-09-21
        相关资源
        最近更新 更多