웹표준 DOCTYPE선언과 Quirks모드

황제낙엽 2011.10.05 10:06 조회 수 : 149

sitelink1  
sitelink2  
sitelink3  
sitelink4  
extra_vars5  
extra_vars6  

DOCTYPE 과 Meta 태그를 브라우저(IE) 버전에 따라 선택적으로 로드해야 하는 경우가 발생하였다.


1. DOCTYPE 선언은 HTML5 이다. 이 DOCTYPE은 HTML5를 지원하는 IE9 에만 적용되어야만 한다.

<!doctype html>

2. IE9 미만의 브라우저는 DocumentMode 가 5 로 동작해야 한다. 이를 위한 Meta 태그정보는 다음과 같다.

<meta http-equiv="X-UA-Compatible" content="IE=5"/>


이를 위해 분기문을 작성한 HTML 코드는 다음과 같다.

<!--[if IE 9]><!doctype html><![endif]-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="ko" lang="ko">

<head>

<!--[if lt IE 9]><meta http-equiv="X-UA-Compatible" content="IE=5"/><![endif]-->

</head>

...

     참고로 Meta정보에서 content 의 IE=5 는 브라우저가 quirks 모드로 동작하도록 강제한다.


Reference

HTML5 Specification

How To Create an IE-Only Stylesheet

IE Conditional Comments 필터링