0

i want to have a centered background image vertically stretched over my website. Works perfectly while there is no scrollbar that's move my centered image, but leave my margin: 0 auto in place. Now my content doesn't line up with my background-image.

Html, Body
{
  width: 100%;
  height: 100%;
  background: url('../Images/page-bgr-top.png')
              center top repeat-x;
  overflow: auto;
}

Body {
  background: url('../Images/page-bgr-content.png')
              center top repeat-y;
  display: block;
  overflow: scroll;
}

#Main-Page
{
  width: 900px;
  margin: 0 auto;
  height: 100%;
  display: none;
}

Tried a different solution by set the background-image and overflow: auto on #Main-Page, too and get some nasty scrollbars right on my website.

MR.ABC
  • 4,712
  • 13
  • 44
  • 88
  • is this site public ? – underscore May 15 '13 at 16:07
  • could you make a demo on http://jsfiddle.net/ ? – Luis May 15 '13 at 16:08
  • @Samitha Hewawasam upp – MR.ABC May 15 '13 at 16:21
  • There's no way of aligning the 2 as they use different values as "center". There is ways round this however. Create a `wrapper` for the entire center column, put the `background` and `margin auto` rules on that instead of body - then place your `header` etc inside that wrapper. That's the most common way to get around this. – naththedeveloper May 15 '13 at 16:28
  • Looking at your code you could even apply the `background` to the `#Main-Page` which is already acting as a wrapper. – naththedeveloper May 15 '13 at 16:29
  • @FDL tried a different solution by set the background-image and overflow: auto on #Main-Page, too and get some nasty scrollbars right on my website. Without overflow: auto http://stackoverflow.com/questions/16565797/100-body-height-content-is-loaded-dynamically – MR.ABC May 15 '13 at 16:35

2 Answers2

0

This is becuase you are adding too many css to the html and body

 Html, Body
        {
          /*width: 100%;*/ removed 
          height: 100%;
          background: url('../Images/page-bgr-top.png')
                      center top repeat-x;
          /*overflow: auto;*/ removed 
        }

        Body {
          background: url('../Images/page-bgr-content.png')
                      center top repeat-y;
          display: block;
          /*overflow: scroll;*/ removed 
        }

        #Main-Page
        {
          width: 900px;
          margin: 0 auto;
          height: 100%;
          display: none;
        }
MR.ABC
  • 4,712
  • 13
  • 44
  • 88
underscore
  • 6,495
  • 6
  • 39
  • 78
0

Solved with javascript. Calculate the width of the scrollbar and add it to the offset of the centered element.

MR.ABC
  • 4,712
  • 13
  • 44
  • 88