Centering A Division

Discussion about CSS related issues.

Centering A Division

Postby paulp575 » Tue Nov 17, 2009 1:38 pm

I am experiencing a problem trying to center a division in an XHTML document.

HTML validator says I can not use <div align="center"> and suggests I use the style of TEXT-ALIGN: Center.

However, that only works for text.

I need to center an entire division.

What to do???

Thanks,
paulp575
paulp575
Rank II - Novice
Rank II - Novice
 
Posts: 42
Joined: Tue Aug 09, 2005 1:20 pm
Location: Spokane WA

Re: Centering A Division

Postby Albert Wiersch » Tue Nov 17, 2009 2:35 pm

I believe I've changed the referred to message to:
[82] The "align" attribute may not be used with the "div" element in a strict XHTML 1.0 document. Instead of align="center", consider using the CSS "text-align: center" instead. To center a block, use the CSS "margin-left: auto; margin-right: auto".

I added this part:
To center a block, use the CSS "margin-left: auto; margin-right: auto".

Try using the CSS "margin-left: auto; margin-right: auto". Please let me know how it works.
Image
Albert Wiersch
User avatar
Albert Wiersch
Site Admin
Site Admin
 
Posts: 2361
Joined: Sat Dec 11, 2004 10:23 am
Location: Near Dallas, TX

Re: Centering A Division

Postby ardeezstyle » Tue Feb 01, 2011 2:36 am

Hi Albert,

when you are talking about centering the using css property margin-left/margin-right auto, it is important that you mention the width for the div as without a specified width the div will not be centered or should I say the centering of the div will not be visible.

Cheers!
ardeezstyle
Rank 0 - Newcomer
Rank 0 - Newcomer
 
Posts: 1
Joined: Tue Feb 01, 2011 2:29 am

Re: Centering A Division

Postby pandaa » Fri Nov 23, 2012 7:56 pm

<div align="center" /> usually works fine, but you can also do <div class="x" /> and refer to external CSS. :)
User avatar
pandaa
Rank 0 - Newcomer
Rank 0 - Newcomer
 
Posts: 2
Joined: Fri Nov 23, 2012 7:43 pm


Return to CSS (Cascading Style Sheets)

Who is online

Users browsing this forum: No registered users and 1 guest

cron