You are here: Re: Layout of self-closing divs - can anyone explain this? « HTML « IT news, forums, messages
Re: Layout of self-closing divs - can anyone explain this?

Posted by David Dorward on 08/03/07 21:53

On Aug 3, 9:28 pm, Jeff Dege <jd...@jdege.visi.com> wrote:

> So off I go to the W3C validator.
>
> Turns out that "<br />" is legal in both html 4.01 and in xhtml 1.0, but
> that "<div />" is legal in xhtml 1.0, but illegal in html 4.01.

In HTML, <br /> means "A br start tag followed by a greater than
sign". Since the end tag for br elements is forbidden (since the
element is empty and can never have any content), this is fine. <div /
> means "A div start tag followed by a greater than sign". Since the
end tag for div elements is required, this is not fine. Additionally
most browsers don't support the / syntax for ending a tag in HTML and
an appendix of the spec warns against using it.

> And now I'm more confused than before, because the document I was having
> trouble with had an xhtml 1.0 DOCTYPE - which means that self-closing
> div's should have been correct code.

Welcome to the wonderful world of trying to write XHTML that works in
the real world. A few user agents considered important by many (such
as Internet Explorer and GoogleBot) don't support XHTML, so you can't
serve your XHTML as application/xhtml+xml if you want it to work. If
you want it to 'work' in such browsers you have to pretend it is HTML
by claiming a content-type of text/html. Depending on how you read the
specs and what you make of statements by the old HTML working group
you can come to conclusions ranging from "You must follow the
guidelines set forth in Appendix C" to "Well, you should follow some
of the guidelines in Appendix C because stuff will break horribly if
you don't, but some you can ignore" to, my personal favorite "XHTML
served as text/html is relatively hard and extremely pointless, stick
to HTML 4.01 until you need XHTML more then you need MSIE support".
(One of the guidelines covers when you should and shouldn't use the
<foo /> syntax).

> But both IE6 and Firefox 2.0 proceeded to treat the page as if they
> weren't.

Because they are treating it as HTML not XHTML since that is what the
Content-Type claims.

--
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация