943,959 Members | Top Members by Rank

Ad:
Jul 18th, 2004
0

div align=center

Expand Post »
What is the difference between <div align="center"> and <div style="text-align:center"> aside from the obvious difference that the latter is CSS?
Similar Threads
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Jul 18th, 2004
0

Re: div align=center

well, I've experimented with it a little before and validated it, aligning a div is not valid strict xhtml 1.0 anyways heh . Other than that I don't know, I know I had different results when I used the div align but none that would make sense. E.g. I set the text-align in my stylesheet to right, this worked but I set the div align to bottom, nothing happened with the text but an image I had in the same div was aligned to the top . Other than that I'm not sure, I think that text-align only applies to text.

once again, my opinion is much ado about nothing.
Reputation Points: 115
Solved Threads: 7
Practically a Master Poster
Slade is offline Offline
633 posts
since Mar 2004
Sep 19th, 2004
0

Re: div align=center

Well, in that example there is no difference, it's just part of a push away from using html attributes for style and towards css.

IF I understand right the current movement is towards having the HTML (to be replaced by XML) describing only the actual content. Then how it is represented on the screen would be described in the css. This way if you only need one data file when using the same content in different ways ex: display on a computer monitor/cell phone/pda/import it into a database, etc....

Of course this only applies when you use an external stylesheet, not when you have the style embedded right in to the tag. I suspect this will one day be depricated as well and is only allowable now to make it easier for people to transition from the old way to the new.
Reputation Points: 13
Solved Threads: 0
Newbie Poster
ZWheel is offline Offline
11 posts
since Sep 2004
Sep 20th, 2004
0

Re: div align=center

I don't think align="" is valid XHTML 1.0 coding. style="text-align: " is, however.
Reputation Points: 12
Solved Threads: 3
Posting Whiz in Training
rixius is offline Offline
212 posts
since Nov 2003
Jul 11th, 2007
0

Re: div align=center

text-align CSS property applies only to the content and not the container. float property helps align the container but has no 'center' attribute. Many have suggested work around methods, which do not work uniformly in all browsers. Perhaps a combination attributes relating to margin, position, and container width could provide a way out. Will appreciate suggestions that address this issue
Reputation Points: 10
Solved Threads: 0
Newbie Poster
majj is offline Offline
1 posts
since Jul 2007
Jul 11th, 2007
0

Re: div align=center

setting a divs margin-left and margin-right to auto is the correct syntax to make a float center to its predecessors if you set its width; the same will work for top and bottom centering with the height set.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mrtony is offline Offline
5 posts
since Jun 2006
Jul 13th, 2007
0

Re: div align=center

align= is deprecated.

And the W3C clowns gave us no good way to center images in nondeprecated ways. They are thinking book and newspaper layout, where images are never centered.

So I do this:
HTML and CSS Syntax (Toggle Plain Text)
  1. <style type="text/css">
  2. .cenx {text-align: center;}
  3. .ceni {clear: both;}
  4. .bxfix {margin: none; border: none; padding: none;}
  5. img {padding: 12px;}
  6. body {padding: 5%;}
  7. </style>
Then for the image itself:

HTML and CSS Syntax (Toggle Plain Text)
  1. <div class="bxfix cenx">
  2. <img src="mine.jpg" alt="my mine" class="ceni" />
  3. </div>
Last edited by MidiMagic; Jul 13th, 2007 at 6:09 am.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Feb 2nd, 2011
0
Re: div align=center
Just make a simple class
<style type="text/css">
#Header{width:600px; background-color:#fff; margin:0 auto; }
</style>

After that just put id="header" in your div.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
ssrawat is offline Offline
1 posts
since Feb 2011
Feb 7th, 2011
0
Re: div align=center
Hi,
HTML and CSS Syntax (Toggle Plain Text)
  1. <div align="center">
align the div to the center position

HTML and CSS Syntax (Toggle Plain Text)
  1. <div style="text-align:center">
align the content of the div to center position.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Bestwebdesign is offline Offline
8 posts
since Jan 2011
Feb 11th, 2011
0
Re: div align=center
Both would perform the same task. When using <div align="center">...</div>, you are fulfilling your objective by using HTML only but in case of <div style="text-align:center">..</div> you are mainly relying on CSS to make the content center aligned. Other than that, there is no difference between the two, I think
Reputation Points: 11
Solved Threads: 6
Light Poster
johnsteve.bravo is offline Offline
39 posts
since Jan 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: how was this done ?
Next Thread in HTML and CSS Forum Timeline: <p> doesn't start a new line?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC