Connecting Tech Pros Worldwide Forums | Help | Site Map

Div in Div Centred Issue

Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#1: Jul 10 '09
I have a div in a div and can't seem to centre it at all, its really annoying me now, I've googled the hell out of it, any ideas?

I've removed all centring code, so this is how the code looks now.

Expand|Select|Wrap|Line Numbers
  1. <div id="board_container">
  2.     <div id="board_inner_container">&nbsp;</div>
  3. </div>
Expand|Select|Wrap|Line Numbers
  1. #board_container {
  2.     float: left;
  3.     width: 800px; /* Defines mx width of board */
  4.     border: 1px #CCCCCC solid;
  5.     clear: left;
  6.     display: inline;
  7. }
  8. #board_inner_container {
  9.     float: left;
  10.     width: 98%;
  11.     border: 1px #CCCCCC solid;
  12.     clear: left;
  13.     display: inline;
  14. }

drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,569
#2: Jul 10 '09

re: Div in Div Centred Issue


Inline elements can not be centered because they are 'inline', that is, just like a sentence in a paragraph. In a block all to their own.
Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#3: Jul 10 '09

re: Div in Div Centred Issue


Makes sense, the only reason I'm using the inline option is to fix the rendering issues with border/padding/margins in IE, is there any way around this?

Tried this and it didn't work either:
Expand|Select|Wrap|Line Numbers
  1. #board_inner_container {
  2.     float: left;
  3.     width: 98%;
  4.     margin-left: auto;
  5.     margin-right: auto;
  6.     border: 1px #CCCCCC solid;
  7.     clear: left;
  8. }
Jezternz's Avatar
Familiar Sight
 
Join Date: Jan 2008
Location: New Zealand
Posts: 128
#4: Jul 10 '09

re: Div in Div Centred Issue


Expand|Select|Wrap|Line Numbers
  1. float:left
Will prevent it from centering as far as I know. Thats the only specific problem I see.
Reply