[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

which DOCTYPE to use?

Posted on 2011-09-28
5
Medium Priority
?
338 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

825 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