4

How do I align this to the center of the page? http://jsfiddle.net/WH7Kf/39/

<div id="lower" style="position:fixed; width:95%; height:5%; background-color:green; ">
a coder
  • 546
  • 4
  • 23

3 Answers3

2

You can either do it this way:

margin-left:auto;
margin-right:auto;

Inside your style or you can also use the positioning property as well:

position:absolute;
top:0%;
left:50%

There isn't a set way to center something, but these are ways that it can be done. Hope this helps!

Brendan
  • 1,399
  • 1
  • 12
  • 18
1

You can align block-level elements using margin:0 auto;:

<div id="lower" style="margin:0 auto; width:95%; height:5%; background-color:green; ">

Demo

This works because you define the margin on the right and left side to be determined automatically, so it'll be in the very middle of the page.

Joeytje50
  • 18,636
  • 15
  • 63
  • 95
1

Here you go.

http://jsfiddle.net/WH7Kf/41/

#lower {
    position:fixed;
    left:0;
    right:0;
    width:95%;
    height:5%;
    background:green;
    margin:auto;
}

If you want to make the div get literary centered both vertical and horizontal, add top:0; and bottom:0;

Wesley Brian Lachenal
  • 4,381
  • 9
  • 48
  • 81