I have been trying to learn HTML/CSS for about a year now as a hobby and I have developed a good base knowledge and I figured before I got to far ahead of myself I would learn all of the proper rules, so I have begin to read HTML 4.01 Specification from the W3C website. I have add the fowling DTD to my HTML code and it causes my style to loose all back ground color. Is the problem in my HTML or could it be in my CSS. I have attached my .php. It works just fine with out the DTD in the first line. Thanx in advance

Lanier

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

Dani AI

Generated

A short, practical diagnosis and checklist based on what happened in this thread.

Adding a standards doctype switches browsers from quirks mode to standards mode. That change alters default box model, default margins, and how backgrounds on the root/body are painted — so a page that looked fine in quirks mode can suddenly lose its background in standards mode. See MDN for how doctypes affect rendering modes: MDN: Quirks Mode and Standards Mode.

Practical checks (in order)

  • Make the doctype the very first thing in the document (no BOM, no whitespace, no comments before it). This is what tells the browser to enter standards mode.
  • Pick one valid markup flavor and stick to it. As warned, do not mix XHTML namespace attributes with an HTML4 doctype. If you follow and move to XHTML, use the correct XHTML doctype and consistent markup.
  • If the background seems missing, try applying/ensuring these CSS basics: set html, body { height: 100%; margin: 0; } and put the page background on body (or explicitly on both html and body) so it fills the canvas. Example:
    html, body { height:100%; margin:0; }
    body { background-color:#f0f0f0; }
  • Validate the page to catch markup errors that standards mode will expose: W3C Validator. Validation often shows what broke when you added the doctype.

Summary: ’s placement tip and ’s suggestion to use XHTML pointed you toward the fix; confirmed the switch worked. The underlying cause is usually the standards-mode behavior change — fixable by consistent markup, correct doctype placement, and the small CSS tweaks above. For reference on doctypes and body-background behavior see MDN: Doctype and MDN: body element.

Recommended Answers

All 5 Replies

I suggest that you move to xhtml.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">

minor bug with this, the doctype is html 4, so xml namespaces are illegal.

bangs head on desk,
read the prior post about shift to xhtml, and messed up
things you do, without thinking, bite you in the bum

switching to XML did the trick, plus another rung in the latter of learning. Thanx MM

Lanier

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.