brown2005 Posted February 21, 2008 Share Posted February 21, 2008 I currently have my site at 750px wide and would like to center it in the middle of the page. Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/ Share on other sites More sharing options...
brown2005 Posted February 21, 2008 Author Share Posted February 21, 2008 i am using float: left; and this makes the website float to the left Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-472602 Share on other sites More sharing options...
ToonMariner Posted February 21, 2008 Share Posted February 21, 2008 Do NOT float it left with css... body { width: 750px; margin: 0 auto; } Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-472660 Share on other sites More sharing options...
phpQv3.0 Posted February 21, 2008 Share Posted February 21, 2008 You need to put all of your body's content in a div "wrapper" and text-align/align it to center. That is the best way to do this. Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-473239 Share on other sites More sharing options...
ToonMariner Posted February 22, 2008 Share Posted February 22, 2008 text-align center is NOT the best way to do this give your element (in this case body) a width (either % or absolute - like px) and set the lft and right margin to auto in your css... THAT IS THE BEST WAY TO DO THIS Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-473574 Share on other sites More sharing options...
TheFilmGod Posted February 22, 2008 Share Posted February 22, 2008 You need to put all of your body's content in a div "wrapper" and text-align/align it to center. That is the best way to do this. Text-align will not center it in Firefox or Opera. Use margin: auto instead. Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-473650 Share on other sites More sharing options...
TheFilmGod Posted February 23, 2008 Share Posted February 23, 2008 It doesn't matter if Firefox aligns the thing center with text-align: center. It isn't standard compliant. So do whatever you want - its your site, but I will tell you that it it's a bad idea. Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-474125 Share on other sites More sharing options...
bronzemonkey Posted February 23, 2008 Share Posted February 23, 2008 Use {margin:0 auto;} on the outer-most containing element to get every browser playing along. Do not listen to the bad advice that recommends using text-align in the css or the align attribute in the html. Text-align is used to align text and not the layout. It will not work unless you are using quirks mode. The align html attribute is also depreciated. If you need to support IE5.* then put you need to do something specific for that browser. It is best to put this in a conditional stylesheet, but every other browser behaves properly (if you are using a valid doctype) even if this code is included in your general stylesheet. /*In an IE5 stylesheet*/ body {text-align:center;} /*centers layout and text in IE5, only centers text in everything else*/ #wrapper {text-align:left;} /*left aligns your text*/ Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-474395 Share on other sites More sharing options...
TheFilmGod Posted February 24, 2008 Share Posted February 24, 2008 The only bad advice; is the advice that bronzemonkey and TheFilmGod is giving you. Text-align center will work fine for this. I also said that "align=center" will work too; like so: <div align="center"> <!-- Body's Content Here --> </div> If you want to listen to less experienced coders; go with the two members above. If you want to make this work and go with an experience designer; you should listen to me. I take that extremely offensively. I deserve an apology for such utter rubbish. Anyway, your method isn't wrong. It works too, but align is an HTML declaration that is deprecated, meaning it isn't the ideal solution. If you use standard complaint browsers like Opera 9.50 beta, you will see that such deprecated declarations have no effect on the actually rendering of the website. Your ego and self confidence is the only thing that supports your statement. You can also try to be modest sometimes, most notably when you speak of such outrageous lies. mod edit: the ludicrous post to which this responded has been removed Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-475362 Share on other sites More sharing options...
bronzemonkey Posted February 24, 2008 Share Posted February 24, 2008 Most of the people here would rather keep the forums civil, inviting, and helpful to those looking for accurate answers. Unfortunately, phpquestioner, you are resorting to slander and some of your advice is simply misleading or not following best practices. It would be appreciated if you could dispense with the aggressive tone and the attacks against professional developers. Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-475416 Share on other sites More sharing options...
AndyB Posted February 25, 2008 Share Posted February 25, 2008 Fortunately the good advice in this thread far outweighs the bad. The discussion really has nowhere left to go. Thread closed. Link to comment https://forums.phpfreaks.com/topic/92253-center-whole-site-in-middle-of-browser/#findComment-475444 Share on other sites More sharing options...
Recommended Posts