Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOCTYPE and CSS 1

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
0
0
GB
Hi,

I have a html page containing a style sheet.
When I have the doctype set to

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> everything is fine

but when i change to <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
the styles are lost and look different. for example with the style

.txt4Grey { font-size : 0.7em; font-weight: normal; color: #2f4f4f; }

this looks different.

can anyone explain what i need to do to keep my styles when changing the doctype?

thansk!
 
The first doctype you listed in incomplete, the second is the correct one. Whilst the first may have produced the style you wanted, all this meant was that you'd written the CSS incorrectly as the browser was running in quirks mode.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Whilst the first may have produced the style you wanted...
More to the point, the first may have produced the style you wanted in one particular browser.

It may appear a backward step to start using a full DOCTYPE if it screws up stuff that was working as you wanted it, but once you start trying to get the page to look right on multiple browsers you'll see the benefit.

Some history: Back in the last century, browser makers pretty much went their own way with how a given piece of CSS and/or HTML should be interpreted. The differences were minor in themselves, but the cumulative effect made it a nightmare to present any but the most simple documents.

The web standards movement introduced a consistent approach that browser makers could follow, which they've all done (albeit to varying degrees). However, they had a problem - what about all the documents created to run under their old rules?

The solution was to have browsers run, by default, in "quirks mode". That is, following their old rules with all the quirks in behaviour that includes. If you want them to follow the standard, you have to include a full doctype. Quirks mode is OK if you only have one browser to support, but if you're writing for the web it's like going back ten years. That's not a good thing.

Once you get into the habit of using a doctype from the start it ceases to be a big issue.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top