Jump to content

centering


dan_t

Recommended Posts

Hello,

I know probably a million people have asked this question, But

Everyone says not to use tables, but to use CSS instead. I can center a web page with no problems at all with tables.

But I can not for the life of me center a site with CSS.

I have tried putting the main page in a div tag named container and everything else inside(in div tags), but it just won't center. I've read up on it, googled it, tried zeroing out the margins. I just can't do it! What's the trick?

I sure could use the help.

Thanks

Link to comment
Share on other sites

Yeh, margin:0 auto; will do the trick, BUT you will find that if you float anything to the left within

that centered div, it will collapse the entire div. For that, you will need to use a stretcher.

 

<div id="container">

 

<div id="floatleftelement"></div>

 

 

<div class="stretcher"></div>

</div>

 

Then just use this class:

 

.stretcher{clear: both; width: 100%; height: 0; line-height: 0; font-size: 0;}

 

Hope that helps.

Link to comment
Share on other sites

I would suggest using firefox and not internet explorer.

 

You could try this code in your css file:

 

html,body{

border:0px;

margin:0px;

width:100%;

height:100%;

}

 

.mainContainer{

width:800px;

min-height: auto;

height:auto;

margin:auto;

}

 

I have used this code and it displayed centered when opened in firefox.

 

You can also try this in your html file, if the above does not work:

 

<div class="mainContainer" align="center">

</div>

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.