Jump to content

Need help to align webpage horizontaly

- - - - -

  • Please log in to reply
3 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi, i want my webpage to be horizontaly aligned in the center of screen. I use this code, but alignment fails:
body{
    background-color:  #d9e2dd;
    width: 1024px;
    height: 100%;
    margin-left: 0px auto;
    margin-right: 0px auto;
}

I would be grateful if someone could help me

#2
da beast

da beast

    Newbie

  • Members
  • PipPip
  • 25 posts
I wouldn't throw the code against the body, use a wrapper!

<div id="wrapper">

<h1>Test</h1>

</div>

here is the css:

/* wrapper to align center of page */
#wrapper {
/*we need to tell the browser the size of the warpper div*/
width:800px;
height:400px;
/*aligns the page to the center horizontal (x)*/
margin-left:auto;
margin-right:auto;
/*aligns the age to the center vertical (y)*/
position: absolute;
top: 50%;
left: 50%;
/*resets the offset (should be half the width and height*/
margin-top:-200px;
margin-left:-400px;
/*allows us to see wrapper*/
background-color:black;
}

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Thanks a lot. That helped

#4
Root23

Root23

    Programmer

  • Members
  • PipPipPipPip
  • 144 posts
Also, note that
margin-left:0px auto; margin-right:0px auto
isn't the correct usage. When you specify a side like that you only supply one value. The better way to do that would simply be
margin:0 auto;
or as da beast used it
margin-left:auto; margin-right:auto

Good luck!
Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users