13

I am trying to center everything within the tag on the page without adding another container within it. My situation doesn't allow me to change the markup that is being generated but I am able to edit the CSS. My overall objective is to create css that allows me to use the zoom tag in IE for the print css (to zoom out), but the way it is currently working, this creates a lot of white space on the right side and I'd like to make sure the content is always centered in the middle.

Ben
  • 1,888
  • 9
  • 25
  • 38

3 Answers3

22

If you're ok with giving the body a fixed width, you can center it by giving it a width and a margin of auto for the left and right margins:

E.g:

body { width: 960px; margin: 0 auto; }
jimr
  • 10,682
  • 1
  • 29
  • 31
1

If you want something like this - http://jsbin.com/emomi3/5/ ...

  body {
    position: relative;
    width: 100%;
    border: 1px solid red;
    display: block;
  }

  body > *  {
    margin: auto;
    width: 500px;
    border: 1px solid blue;
    display: block;
    overflow: auto;
  }

  body > script {
    display: none
  }

(The borders are just in for illustration purposes)

Dr. Frankenstein
  • 4,394
  • 7
  • 30
  • 48
0

if you use primefaces ... , I recommend to you to add !important like this :

body { 
    width: 1280px;
    height: 1024px;
    margin: 0 auto !important;
}
Karim Oukara
  • 2,508
  • 8
  • 36
  • 49