div align="center"

Reply

Join Date: Jul 2008
Posts: 101
Reputation: ingeva is an unknown quantity at this point 
Solved Threads: 9
ingeva ingeva is offline Offline
Junior Poster

div align="center"

 
0
  #1
Oct 12th, 2008
The above HTML code is sometimes ignored by FireFox, but worse: It's not even allowed in XHTML1.0 Strict.

I have updated my sites to be "Strict" compatible, except for this little thing which is important enough. The problem is that I have found nothing to replace it.

In this example:

HTML and CSS Syntax (Toggle Plain Text)
  1. <a href="http://greatday.com/motivate/index.html">
  2.  
  3. <img style="width:18em;"
  4.  
  5. src="http://greatday.com/motivate/dmsum.gif" alt="Daily Motivator" title="Daily Motivator" /></a>

the image should be centered, but even if I enclose it by a div with text-align:center,
FireFox places the image to the far left. This happens with many other objects as well, especially if they are defined as block elements.

Surely it shouldn't be like this?
Or rather, how can we continue having centered objects while confirming to the newer standards?

I could write a table-like construct using divs and css, but that would be extremely clumsy for a little thing like this. I'm looking for a simple solution, where HTML defines the content and css the style!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: div align="center"

 
0
  #2
Oct 12th, 2008
Here is an interesting statistic:
Yahoo has hundreds of HTML/CSS errors that don't comply with standards.
No website is absolutely prefect when it comes to standards. (Not like I'm volunteering to check!!!). I would suggest simply using a less-strict standard. I usually code in XHTML 1.0 Transitional.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: div align="center"

 
0
  #3
Oct 12th, 2008
To center a block-type object, within another block type object, use this code on the object that you want to be centered ( i.e. on the inner object ):
HTML and CSS Syntax (Toggle Plain Text)
  1. style="margin-left:auto;margin-right:auto;"
although, tbh, text-align:center; really should work, since an image isn't supposed to be a block-type object.

anyway, for best compatibility, use text-align:center; on the outer object, and margin-left:auto;margin-right:auto; on the image.
Last edited by MattEvans; Oct 12th, 2008 at 11:14 pm.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 101
Reputation: ingeva is an unknown quantity at this point 
Solved Threads: 9
ingeva ingeva is offline Offline
Junior Poster

Re: div align="center"

 
0
  #4
Oct 13th, 2008
Originally Posted by MattEvans View Post
To center a block-type object, within another block type object, use this code on the object that you want to be centered ( i.e. on the inner object ):
HTML and CSS Syntax (Toggle Plain Text)
  1. style="margin-left:auto;margin-right:auto;"
although, tbh, text-align:center; really should work, since an image isn't supposed to be a block-type object.

anyway, for best compatibility, use text-align:center; on the outer object, and margin-left:auto;margin-right:auto; on the image.
Thanks! I'll try that! text-align:center doesn't work alone, so probably this was what I needed. I often define images as block because it separates from text with a newline without haveing to use <br /> for instance.

Thank you very much!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 29
Reputation: cpeeyush1 is an unknown quantity at this point 
Solved Threads: 2
cpeeyush1 cpeeyush1 is offline Offline
Light Poster

Re: div align="center"

 
0
  #5
Oct 13th, 2008
always use
margin-left:auto;
margin-right:auto;

because if u use this code rather then your one then if in any case if browser screen size is change due to any reason then the left and right margin are auto set for equal value according to the size of screen and this one is a better idea or one of the best

and one importent thing is that you should use external css rather then this internal one

-PC(INDIA)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: wickedsunny is an unknown quantity at this point 
Solved Threads: 4
wickedsunny wickedsunny is offline Offline
Junior Poster in Training

Re: div align="center"

 
0
  #6
Oct 15th, 2008
ok let me make it easier to u in all browsers. jsut use this style in the div .
style="margin:0 auto; text-align:center;"
this margin 0 auto is for firefox and flock, while the text align will work in browsers like ie opera etc cheers
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC