开发者

Appropriate DTD to fix this issue?

开发者 https://www.devze.com 2023-03-14 20:40 出处:网络
I was having problems with cross-browser compatibility and found out a plugin called \"Browser Compatibilty Detector\" for Chrome. It recommended adding a DTD to renders the page in standards mode.

I was having problems with cross-browser compatibility and found out a plugin called "Browser Compatibilty Detector" for Chrome. It recommended adding a DTD to renders the page in standards mode.

I added this:

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

It brought new issues and fixed others but at least now all browsers are working kinda the same.

However it's still recommending adding a DTD for another issue:

In IE6 IE7(Q) IE8(Q), the container will be enlarged when its 'width' or 'height' is not big enough to hold all its contents
Content box's size in Chrome: 1366 * 0, in IE: 1366 * 653.
Suggestion: Use a DTD that makes开发者_高级运维 the page rendered in Standards Mode, so that only IE6(S) will be affected.

What type of doctype should I add? I didn't even know they existed until 5 minutes ago so I have no idea what to write.


I suggest you add the HTML5 docytype only

<!DOCTYPE html>

so that your code will be future friendly AND then start pinpointing and fixing the cross-browser issues that crop up.

Also, if you do not need to be supporting legacy browsers like IE6 and IE7, then you can start to ignore them. Check you stats to see if support is even merited.


<!DOCTYPE ... > was originally an SGML directive that defined (directly or by reference) the language of the document and its possible structure. Nowadays it is probably most often mentioned in discussions on what rendering/parsing mode it activates in the browser.

http://hsivonen.iki.fi/doctype/

That is a generally nice article on different doctype declarations for HTML documents. It has some background information about different modes and a table denoting what mode is activated by what doctype. Generally the best practice is to use a doctype declaration that matches your HTML/XHTML version (or one compatible with yours) and triggers the standards mode in browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号