Solved

which DOCTYPE to use?

Posted on 2011-09-28
5
318 Views
Last Modified: 2012-05-12
I have the following html:

<html>
<head>
<title>Test div</title>
</head>
<body>
<DIV>

<div id=MbrMenu style="z-index:2; position:absolute; top:185; left:180; visibility: visible">
HELLO WORLD!
</div>

</DIV>
</body>
</html>

If I use no DOCTYPE, or if I use: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">, this html displays just fine (IE 8 and Firefox 6.0.2). The text in the MbrMenu div displays at the desired 180,185 position. However, if I use:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

the top/left directives are ignored and the text displays at the upper left (0,0).

I thought this latter DOCTYPE was more up-to-date and I have been using it extensively for quite a while. Lately, I had to modify a program using the absolute placed DIVs and replaced the previous DOCTYPE with the latter.

Has something changed in the z-index/positioning specifications? Is this doctype incorrect? If so, what *should* I be using?I need urgent help on this because I have a whole series on pop-down sub-menus that rely on the ability to position things on the page.
0
Comment
Question by:jmarkfoley
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36720473
Add 'px' to the end of the positions:

<html>
<head>
<title>Test div</title>
</head>
<body>
<DIV>

<div id=MbrMenu style="z-index:2; position:absolute; top:185px; left:180px; visibility: visible">
HELLO WORLD!
</div>

</DIV>
</body>
</html>

Open in new window

0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36720631
Basic reason it doesn't work with the xhtml doctype is that if you don't have a valid doctype (which your other doctype is not), then browsers will render the document in what is called 'quirks mode'. This means it is much more lenient and liberal with what it allows as acceptable syntax. If you put a valid doctype in, the browser my be a lot more stubborn as to what it allows for syntax. Requiring a measurement increment on some css attributes is just one of those pieces of syntax.
0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 36720764
MacAnthony: adding the px worked.

in your 36720631 post, are you saying that the doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

is wrong? If so, what would you recommend?
0
 
LVL 11

Accepted Solution

by:
MacAnthony earned 500 total points
ID: 36722866
Sorry if I wasn't clear. I meant the <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> doctype wasn't valid. Saying that isn't valid isn't entirely true, but it is missing some attributes like the version. The xhtml one appears to be correct which is why it would break your page. A list of valid doctypes can be found here:

http://www.w3.org/QA/2002/04/valid-dtd-list.html
0
 
LVL 1

Author Closing Comment

by:jmarkfoley
ID: 36812746
Thank! the "px" thing just didn't occur to me, tho' it should have!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question