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
https://forums.phpfreaks.com/topic/143387-centering/
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
https://forums.phpfreaks.com/topic/143387-centering/#findComment-752312
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
https://forums.phpfreaks.com/topic/143387-centering/#findComment-752828
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.