PDA

View Full Version : Simple Question- XHTML DIV



adamorjames
Nov 19th, 2006, 06:04 AM
Can you end a DIV with no text in it like this--> <div id="example" />

harbingerOTV
Nov 19th, 2006, 06:14 AM
nah. that doesnt do anything.
something like:


<div id="example">
</div>


divs have a closing to them so the <div /> isnt rigth. it's <div></div> unlike things like hr's ( <hr /> )

Arbitrator
Nov 19th, 2006, 08:14 AM
<div/> is a valid XML construct, just like <br></br> is valid. That slash at the end is simply short-hand for the closing tag when the element contains no content. However, there may be resulting compatibility issues with those syntaxes, thus </div> and <br /> are safer for use. I would stick with the traditional syntax if youíre serving your XHTML with the HTML media type instead of the XHTML media type (as you almost certainly are) since the document will not be read by an XML parser.

adamorjames
Nov 19th, 2006, 03:48 PM
I end it as if it has text in it like --> <div class="example"></div>
I was just wondering if I could shorten that, thanks for information. Arbitrator I'm not totally sure what you mean by serving it as html media, I use "application/xhtml+xml" not "text/html".

_Aerospace_Eng_
Nov 19th, 2006, 06:56 PM
You may think you are passing the right media type but merely changing the meta content type does not work. Post a link to your page and we can tell you if you are passing the application/xhtml+xml header or not.

Arbitrator
Nov 20th, 2006, 12:01 AM
Arbitrator I'm not totally sure what you mean by serving it as html media, I use "application/xhtml+xml" not "text/html".Open your page in Firefox, right‐click it, and select View Page Info. The value for the Type field should be application/xhtml+xml. Another simple test is to open it in Internet Explorer; if the page displays, then you are not using the XHTML media type since IE doesnít support it.

adamorjames
Nov 20th, 2006, 12:21 AM
Okay, the type is text/html but the content-type is application/xhtml+xml, so what does that mean exactly?

Arbitrator
Nov 20th, 2006, 01:15 AM
Okay, the type is text/html but the content-type is application/xhtml+xml, so what does that mean exactly?If you have the following,Ö

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>

Ö know that that you canít set the fileís media (content) type with a meta element. You should change the content attribute value back to text/html to reflect that with which the document is actually being displayed. To display the page with the XHTML media type, you need to alter your serverís settings so that files with a *.html file extension are served as application/xhtml+xml. Of course, it would be better if you simply used the *.xhtml or *.xht extensions to induce the correct media type instead. I donít believe that you can set the character encoding using a meta element either when XHTML is displayed correctly; you need to use an XML declaration prior to your doctype declaration, otherwise it defaults to UTF‐8.

<?xml version="1.0" encoding="UTF-8"?>

If you choose not to use an XML declaration, you wonít be able to use encodings like ISO 8859‐1.

adamorjames
Nov 20th, 2006, 01:33 AM
Thank you so much! I've always wondered if I should save it with an xhtml extension!!! It now shows application/xhtml+xml as the type but I thought it wasn't suppose to work in IE, it works in IE 6 for me. What do encodings do, I never understood them and are you suppose to end that xml declaration?

EDIT
Nevermind, IE6 opens Mozilla Firefox to open the XHTML. Does XHTML work in IE7?

Arbitrator
Nov 20th, 2006, 02:08 AM
What do encodings do, I never understood them and are you suppose to end that xml declaration?Character encodings define what characters are allowed in the document. You typically see special characters escaped as character entities like &copy; because a document is encoded in a format that doesnít accept such characters when typed directly. If you try directly inputting a character and the document is encoded wrongly, you get question marks in Firefox and gibberish in Internet Explorer for those characters. You also see that same effect when you visit a page where you donít have the character set installed; for example, an Arabic or Asian Website. You wonít see that problem often though except in the second case, since if Web authors know how to encode their page correctly, they tend to do so, and if they donít, then they tend not to do so and the browser makes an educated guess (even though, as I understand it, theyíre not supposed to guess).

UTF‐8 tends to be fine for everything though; I can type Japanese and other special characters directly into a document without problems. You just need to specifically save the document in UTF‐8 format; Microsoft Notepad can do this but itís not recommended to use that program since it leaves you no choice but to save the file with a byte order mark (BOM), which can cause problems with browsers and PHP. You can look that up if you want more information.


Does XHTML work in IE7?No. They added recognition for the XML declaration to Internet Explorer 7 so that it doesnít trigger backward‐compatibility (quirks) mode, but currently Internet Explorer still doesnít understand true XHTML.