1

I am trying to put a label in middle/center part of the page and button at bottom/center part of the page but struggling. The jsfiddle for this

Below is the HTML code snippet,

<div style="text-align:center;vertical-align:middle;">
    <label id="lblStatus">Please wait...</label>
</div>
<button id="btnClose" value="Close" onclick="window.close();" style="position:absolute; bottom:0; text-align:center; width:80px"></button>
user2669989
  • 308
  • 1
  • 2
  • 15

5 Answers5

0

This should work:

<div style="text-align:center;vertical-align:middle;">
    <label id="lblStatus" style="position: absolute; top: 50%;">Please wait...</label>
</div>
<div style="text-align: center;">
    <button id="btnClose" value="Close" style="position:absolute; bottom:0; text-align:center; width:80px">A button</button>
</div>

Here's a jsfiddle.

Nagra
  • 466
  • 3
  • 8
0

HTML:

<div id="labelHolder">
    <label id="lblStatus">Please wait...</label>
</div>

<button id="btnClose" value="Close" onclick="window.close();"></button>

CSS:

#labelHolder {
    text-align:center;
    vertical-align:middle;
}

#labelHolder #lblStatus {
    margin: auto;
    position: absolute;
    top: 50%;
    left: 0;
    bottom: 0;
    right: 0;
}

#btnClose {
    position:absolute;
    bottom:0;
    left:50%;
    margin-left:-40px;
    text-align:center;
    width:80px
}

jsfiddle: http://jsfiddle.net/98vLu/

abdhoms
  • 173
  • 1
  • 11
0
<div style="text-align:center; position: absolute;top:50%;width:100%;">
    <label id="lblStatus">
        Please wait...
    </label>
</div>

<div style='text-align:center;position:absolute;bottom:0; width:100%;'>
<button id="btnClose" value="Close" onclick="window.close();" style=" bottom:0; text-align:center; width:80px"></button>

jsfiddle

Adding position:absolute; gives a lot of flexibility when trying to position something.

tylerlindell
  • 1,545
  • 2
  • 17
  • 20
0

For vertical center alignment, you will have better height control by using display: table-cell.

For Example: http://jsfiddle.net/Ljht7/8/

Trav L
  • 14,732
  • 6
  • 30
  • 39
0

This is it ... simple, standard and clean ... no scripts, no fixed sizes ...

Try this for both ... this is a standard solution to center an element vertically/horizontally ... you could use it for the "please wait" and us a relative text centered div for the button ... good luck

<div style="
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
text-align: center;
overflow: hidden;
white-space: nowrap;">
    <div style="
        position: relative;
        display: inline-block;
        height: 100%;
        vertical-align: middle;"></div>
    <div style="
        position: relative;
        display: inline-block;
        vertical-align: middle;">
THIS IS CENTERED ONLY WITH CSS<br/>
parent's position: absolute; is only an example, it can be relative<br/>
Marcelo Villarreal :D</div>
</div>