Solved

which DOCTYPE to use?

Posted on 2011-09-28
5
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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…

690 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