Jump to content

centering a full page


Yeodan

Recommended Posts

I've been searching for like two hours now and can't figure it out.

 

I just want to center my entire page, using divs, with css. I also want it to work in most browsers.

 

I've found sites that show you how it's done, but there's no explanation and it's too complicated to just copy it.

I've also found sites that show it, but when I try it it just doesn't work.

 

 

here's my css if that helps:

I've been trying to get it to work so there might be some strange things in it.

body {
background-color: #F5FFF5;
color: #000000;
    text-align: center;
}
TD {
FONT-FAMILY: Verdana, Arial;
FONT-SIZE: 9pt;
color: #000000;
}
A {
COLOR: #0000FF; TEXT-DECORATION: none;
}
A:hover {
COLOR: #6969FF; TEXT-DECORATION: none;
}
.input {
BACKGROUND-COLOR: #006600;
COLOR: #CCFFCC;
border-style: solid;
border-color: #66FF00;
FONT-FAMILY: Verdana, Arial;
FONT-SIZE: 9pt;
TEXT-DECORATION: none;
}


container {
    margin: 0 auto;
text-align: left;
}

#banner {
    left: 25px;
    top: 10px;
position: absolute;
}

#avatar {
left: 15px;
    top: 100px;
position: absolute;
}

#link {
    left: 25px;
    top: 375px;
position: absolute;
}

#news {
left: 200px;
    top: 100px;
    height: 171px;
    width: 370px;
    position: absolute;
    background-image: url("../images/testbg.png");
}

#update {
left: 588px;
    top: 100px;
    height: 171px;
    width: 100px;
    position: absolute;
    background-image: url("../images/testbg.png");
}

#main {
left: 200px;
    top: 365px;
    height: 50px;
    width: 100px;
position: absolute;
}

Link to comment
Share on other sites

Actually, you could center the page. I don't recommend using this technique. As absolute positioning is incorrect to center things!

 

Enclose all your contents within a div called - "html-center"

 

<body>

<div id="html-center">

      .......... all your body contents

</div>

</body>

 

In your css:

 

#html-center {

  width: (-specify width-)px; /* like - width: 800px; */

  margin: 0 auto;

  position: relative;

}

 

There you go! It'll center;

Link to comment
Share on other sites

Actually, you could center the page. I don't recommend using this technique. As absolute positioning is incorrect to center things!

 

Enclose all your contents within a div called - "html-center"

 

<body>

<div id="html-center">

      .......... all your body contents

</div>

</body>

 

In your css:

 

#html-center {

  width: (-specify width-)px; /* like - width: 800px; */

  margin: 0 auto;

  position: relative;

}

 

There you go! It'll center;

That will only center it for Firefox, Opera, etc. but not IE

 

to center in IE just add

text-align:center;

to body then in the #html-center reset it with

text-align:left;

Link to comment
Share on other sites

Actually, you could center the page. I don't recommend using this technique. As absolute positioning is incorrect to center things!

 

Enclose all your contents within a div called - "html-center"

 

<body>

<div id="html-center">

      .......... all your body contents

</div>

</body>

 

In your css:

 

#html-center {

   width: (-specify width-)px; /* like - width: 800px; */

   margin: 0 auto;

   position: relative;

}

 

There you go! It'll center;

That will only center it for Firefox, Opera, etc. but not IE

 

to center in IE just add

text-align:center;

to body then in the #html-center reset it with

text-align:left;

You are wrong. It will work fine in IE if you set a valid DOCTYPE.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.