Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

which DOCTYPE to use?

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

618 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