CSS用于集中屏幕底部的HTML5 div

时间:2013-05-21 12:28:33

标签: css html5 css3 windows-8 winjs

我有以下HTML5文档:

<canvas id="myCanvas">
</canvas>
<img id="logo" src="/images/logo.png" style="visibility:collapse" />
<div id="adControl" style="width: 728px; height: 90px; border: solid 1px red; visibility:visible;"
    data-win-control="MicrosoftNSJS.Advertising.AdControl"
    data-win-options="{applicationId: 'xyz', adUnitId: '123'}">
</div>

我正在尝试将adcontrol显示在屏幕底部的中心,画布下方。这是我的CSS:

#adControl {   

    float:left; 

    margin: 0px auto;

}

#myCanvas {

    float:left;

}

我已尝试过广告控制的各种保证金组合,但似乎无法将其集中化。

7 个答案:

答案 0 :(得分:1)

在Windows 8的WinJS应用程序中,您可以使用-ms-grid和-ms-flexbox来实现此目的。

HTML:

<div class="mypage fragment">
    <header aria-label="Header content" role="banner">
        <button class="win-backbutton" aria-label="Back" disabled type="button"></button>
        <h1 class="titlearea win-type-ellipsis">
            <span class="pagetitle">My Page</span>
        </h1>
    </header>    
    <section role="main">
        <canvas id="myCanvas">
        </canvas>
        <div class="ad-area-host">
            <div class="ad-area" style="width: 728px; height: 90px; border: solid 1px red; visibility:visible;"
               data-win-control="MicrosoftNSJS.Advertising.AdControl"
               data-win-options="{applicationId: 'xyz', adUnitId: '123'}">
            </div>
        </div>
    </section>
</div>

的CSS:

// some of the css for fragment and section[role=main] already exists in default.css
.fragment 
{
    width: 100%;
    height: 100%;
    /* Define a grid with rows for a banner and a body */
    -ms-grid-columns: 1fr;
    -ms-grid-rows: 128px 1fr;
    display: -ms-grid;
}

.mypage.fragment section[role=main] 
{
    -ms-grid-row: 2;
    display: -ms-grid;
    -ms-grid-rows: 1fr auto;
    -ms-grid-columns: 1fr;
}

.ad-area-host
{
    -ms-grid-row: 2;
    height: 90px;
    display: -ms-flexbox;
    -ms-flex-direction: column;
    -ms-flex-align: center;
}

我没有测试过这个。试试看。我们的想法是使用网格来对齐底部的广告区域主机。然后,使用-ms-flexbox在ad-area-host div中显示以使广告区域居中。

答案 1 :(得分:0)

#adControl {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translate( -50%, 0);
    -ms-transform: translate( -50%, 0); 
    -webkit-transform: translate( -50%, 0);
}
你是说这样的意思吗?

答案 2 :(得分:0)

或者你的意思是this

#adControl {   
position: relative;
width: 728px;
margin: 0px auto;
top: 200px;
margin-top: 100px;
height: 90px;
border: solid 1px red;
visibility:visible
}

答案 3 :(得分:0)

您实际上应该从下面的div中移除float: left以使其位于中心。

试试这个:

 #adControl { 
      clear:left; 
      margin: 0px auto; 
 }

答案 4 :(得分:0)

嗨,看看这个,

http://jsfiddle.net/SnjWs/1/

让我知道是否有帮助

#adControl {
    width:728px;
    margin: 0px auto;
    height:90px;
    border: solid 1px red;
    visibility:visible;
}
#myCanvas {
    width:200px;
    border:1px solid black;
}

<canvas id="myCanvas"></canvas>
<img id="logo" src="/images/logo.png" style="visibility:collapse" />
<div id="adControl" data-win-control="MicrosoftNSJS.Advertising.AdControl" data-win-options="{applicationId: 'xyz', adUnitId: '123'}"></div>

答案 5 :(得分:0)

你的意思是这样吗?

.box {
    width:1024px;
    margin: 0px auto;
}
#adControl {   
    position:fixed;
    bottom:0;
    width: 728px; 
    height: 90px;
    border: solid 1px red; 
    visibility:visible;
}

答案 6 :(得分:0)

我没有尝试使用画布,但它不应该太重要。 我已将此用于底部并居中显示728x90的广告


.wideAdTile {
    position: fixed;
    bottom: 0;
    left: 50%;
    margin-left: -364px; /*negative half the width of the ad*/
    width: 728px;
    height: 90px;
    z-index: 1;
}

和html


<div class="wideAdTile" id="wideAd"
    data-win-control="MicrosoftNSJS.Advertising.AdControl"
    data-win-options="{ applicationId: 'd25517cb-12d4-4699-8bdc-52040c712cab', adUnitId: '10043000' }">
</div>