2008년 9월 20일 토요일

[CSS]인터넷 익스플로러 조건 주석문

조건 주석문은 윈도우용 IE5 가 나오면서 선보인 기능으로서 그 이후에 나온 윈도우용 모든 버전에서 지원하고 있습니다.
특정 스타일시트 IE5 이상 브라우저에 적용하려면 다음과 같은 코드를 (X)html 문서 헤드 부분에 넣으면 됩니다.

 

<!– [if IE]
<style type=”text/css”>
@import (”style.css”);
</style>
–>


위와 같이 할경우 IE5 이상 버전에서는 style.css 를 읽어드리고, 나머지 브라우저에서는 주석문으로 인식합니다.
IE5 같은 특정 버전의 브라우저가 대상이 되도록 할려면 아래와 같은 방법으로 할 수 있습니다.

 

<!– [if IE 5]
<style type=”type/css”>
@import (”style.css”);
</style>
–>


5.5 이상 브라우저를 대상으로 할려면

<!– [if gte IE 5.5000]

 

IE5와 5.5를 대상으로 할려면

<!– [if it IE 6]

 

위와 같은 기법들은 아주 잘 동작하면서 상대적으로 외우기도 쉽습니다. 단 이 주석문은 css 파일이 아니라 html에 써야 합니다. 그러므로 특정 브라우저를 더이상 지원하지 않게 될 경우 모든 페이지마다 해당 주석문을 제거해야 합니다.

 

<p><!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->
<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]-->
<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->
</p>

댓글 없음:

댓글 쓰기