3 replies [Last post]
_com
Offline
Regular
Last seen: 15 years 47 weeks ago
Joined: 2005-01-04
Posts: 31
Points: 0

#maindiv {position: relative; }

#nesteddiv{ padding: 0px; margin: o auto; height: 300px; width: 600px;}

will this always center a nested div

MacStruan
Offline
newbie
Last seen: 15 years 47 weeks ago
Timezone: GMT-8
Joined: 2005-01-06
Posts: 6
Points: 0

center a nested div

If you make this change:

#maindiv { position: relative; text-align: center; }

Then the margin:auto attribute of #nesteddiv will cause the #nesteddiv to be centered.

_com
Offline
Regular
Last seen: 15 years 47 weeks ago
Joined: 2005-01-04
Posts: 31
Points: 0

center a nested div

not bad for a newbie

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 47 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

center a nested div

The margin auto should align the div for any 'standards compliant browser' text-align:center will align a block in 'Non standards aware browsers' such as IE5 which don't understand 'auto' but you would need to re-align the text on a child div.

_com what does the comment "Not bad for a Newbie" mean ?
Not wishing to cause offence but the three topics that you have started have been confusingly worded and are difficult to reply to.
could you add a little more depth and clarity to the questions; as at the moment I have that nagging feeling of a troll at work , forgive me if I offend.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me