Skip to content Skip to sidebar Skip to footer

CSS To Centralise A HTML5 Div At The Bottom Of The Screen

I have the following HTML5 document:

Solution 1:

In WinJS app for windows 8, you can use -ms-grid and -ms-flexbox to achieve this.

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

I have not tested this. give it a try. the idea is to use grid to align ad-area-host at bottom. then, use -ms-flexbox display in ad-area-host div to center the ad-area.


Solution 2:

Do yo mean something like this?

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

Solution 3:

#adControl {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translate( -50%, 0);
    -ms-transform: translate( -50%, 0); 
    -webkit-transform: translate( -50%, 0);
}

Do you mean something like this?


Solution 4:

Or do you mean something like this ?

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

Solution 5:

You should actually remove float: left from the below div to make it in center.

Try this:

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

Post a Comment for "CSS To Centralise A HTML5 Div At The Bottom Of The Screen"