HostGator Hosting
 
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Web Directory

Go Back   Webmaster Forum > Designing and Developing Websites > Web Design

Web Design Discussions and help on Website Design, HTML, CSS, xHTML, DHTML, etc...

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 04-02-2008, 01:21 AM
ablaye's Avatar
ablaye ablaye is offline
WMG Sheriff

 
Join Date: Feb 2007
Posts: 282
iTrader: (0)
ablaye is on a distinguished road
Default How do you center a div?

Been struggling with this for the last few days.
I have a div section that I would like to have centered on the page.
Code:
<div style="background-color:#EFEDE9; border-top:2px solid #D1D1E1; border-right:2px solid #D1D1E1; border-left:2px solid #D1D1E1; text-align:center;margin:0 auto;">
Want this section to be centered!
</div>
It works fine on IE6 and IE7 but on Firefox, the div does not appear centered.

I tried to include the div code in a table that I had centered but it still did NOT work.
The code:
Code:
<table cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td align="center">
<div style="background-color:#EFEDE9; border-top:2px solid #D1D1E1; border-right:2px solid #D1D1E1; border-left:2px solid #D1D1E1; text-align:center;margin:0 auto;">
Want this section to be centered!
</div>
</td></tr>
</table>
still did NOT get the div centered.

I don't know what else to try.
If anyone has any suggestions, please let me know.
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block

  #2 (permalink)  
Old 04-02-2008, 01:37 PM
chrishirst's Avatar
chrishirst chrishirst is offline
WMG Sheriff
 
Join Date: Nov 2007
Posts: 170
iTrader: (0)
chrishirst is on a distinguished road
Default

http://www.webmaster-talk.com/css-fo...r-website.html
__________________
And how can we win, when fools can be kings
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 12:01 PM
Jacob's Avatar
Jacob Jacob is offline
WMG Deputy Sheriff
 
Join Date: Apr 2008
Posts: 158
iTrader: (0)
Jacob is on a distinguished road
Default

Hm, I would have said google.com

CSS?
Code:
<style>

div.tag {
text-align:center;
}
</style>

<div style="tag">stuff</dive>
Reply With Quote
  #4 (permalink)  
Old 04-12-2008, 04:51 AM
bdude bdude is offline
WMG Newcomer
 
Join Date: Apr 2008
Posts: 8
iTrader: (0)
bdude is on a distinguished road
Default

That CSS will just center the text, to center the DIV use:
Code:
div {
margin: 0 auto;
}
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 12:34 AM
Jacob's Avatar
Jacob Jacob is offline
WMG Deputy Sheriff
 
Join Date: Apr 2008
Posts: 158
iTrader: (0)
Jacob is on a distinguished road
Default

Quote:
Originally Posted by bdude View Post
That CSS will just center the text, to center the DIV use:
Code:
div {
margin: 0 auto;
}
Well then thats where he fucked up too ><

Quote:
<div style="background-color:#EFEDE9; border-top:2px solid #D1D1E1; border-right:2px solid #D1D1E1; border-left:2px solid #D1D1E1; text-align:center;margin:0 auto;">
Reply With Quote
  #6 (permalink)  
Old 06-05-2008, 01:35 PM
Wolverine's Avatar
Wolverine Wolverine is offline
WMG Resident Alien
 
Join Date: Apr 2008
Posts: 50
iTrader: (0)
Wolverine is on a distinguished road
Default

Cool tips, thanks. I have had to deal with this recently as well.
Reply With Quote
  #7 (permalink)  
Old 07-15-2008, 01:35 PM
dvrtmcc dvrtmcc is offline
WMG Newcomer
 
Join Date: Jul 2008
Posts: 9
iTrader: (0)
dvrtmcc is on a distinguished road
Default Tricky question

This is a tricky question and so simple. IE will not show regular
Quote:
margin: 0 auto
This will work in in all browsers:

Quote:
body {
position:absolute;
left:50%;
margin-left:-293px;
Reply With Quote
  #8 (permalink)  
Old 07-18-2008, 02:46 PM
chrishirst's Avatar
chrishirst chrishirst is offline
WMG Sheriff
 
Join Date: Nov 2007
Posts: 170
iTrader: (0)
chrishirst is on a distinguished road
Default

Quote:
Originally Posted by dvrtmcc View Post
This is a tricky question and so simple. IE will not show regular
Actually
Code:
margin: 0 auto
works perfectly well in IE from 6 onwards provided you have a FULL, valid doctype
__________________
And how can we win, when fools can be kings
Reply With Quote
  #9 (permalink)  
Old 07-25-2008, 06:35 PM
tonyf12 tonyf12 is offline
WMG Newcomer

Recent Blog: jQuery
 
Join Date: Jul 2008
Posts: 29
iTrader: (0)
tonyf12 is on a distinguished road
Default

To get it to work in IE older than 6 (and 6 in quirks mode) aswell as modern browsers you will need something like this:

HTML Code:
<div id="outer-container">
<div id="inner-container">

... Your content here ...

</div>
</div>
and the CSS

Code:
.outer-container {
margin:0 auto;
text-align:center;
}
.inner-container {
text-align:left;
}
Older versions of IE (not sure which ones) treat text-align as a general align property.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT. The time now is 06:24 PM.



Freelance Web Designers
Work At Home Forum
Ad Marketplace
Online Deals and Bargains
midPhase Web Hosting - $7.95/month - 500 GB B/W! Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0