当前位置: 移动技术网 > IT编程>网页制作>CSS > 不同版本IE使用不同css(css条件注释语句用法)

不同版本IE使用不同css(css条件注释语句用法)

2017年12月08日  | 移动技术网IT编程  | 我要评论

程亚丽最新消息,狄更斯,三河市教育局

一、条件注释简介
1.ie中的条件注释(conditional comments)对ie的版本和ie非ie有优秀的区分能力,是web设计中常用的hack方法。
2.条件注释只能用于ie5以上。
3.如果你安装了多个ie,条件注释将会以最高版本的ie为标准。
4.条件注释的基本结构和html的注释(<!– –>)是一样的。因此ie以外的浏览器将会把它们看作是普通的注释而完全忽略它们。
5.ie将会根据if条件来判断是否如解析普通的页面内容一样解析条件注释里的内容。
二、条件注释属性
gt : greater than,选择条件版本以上版本,不包含条件版本
lt : less than,选择条件版本以下版本,不包含条件版本
gte : greater than or equal,选择条件版本以上版本,包含条件版本
lte : less than or equal,选择条件版本以下版本,包含条件版本
! : 选择条件版本以外所有版本,无论高低
1、css if hack条件语法
< !--[if ie]> only ie <![endif]-->
仅所有的win系统自带ie可识别

< !--[if ie 5.0]> only ie 5.0 <![endif]-->
只有ie5.0可以识别

< !--[if gt ie 5.0]> only ie 5.0+ <![endif]-->
ie5.0包换ie5.5都可以识别

< !--[if lt ie 6]> only ie 6- <![endif]-->
仅ie6可识别

< !--[if gte ie 6]> only ie 6/+ <![endif]-->
ie6以及ie6以下的ie5.x都可识别

<!--[if lte ie 7]> only ie 7/- <![endif]-->
仅ie7可识别

< !--[if gte ie 7]> only ie 7/+ <![endif]-->
ie7以及ie7以下的ie6、ie5.x都可识别

<!--[if ie 8]> only ie 8/- <![endif]-->
仅ie8可识别

<!--[if ie 9]> only ie 9/- <![endif]-->
仅ie9可识别

注:在 if  后加 lt gte有不同效果 (参加其它参数同理)
<!–[if ie 8]> = ie8 仅ie8可识别
<!–[if lt ie 8]> = ie7或更低版本
<!–[if gte ie 8]> = 高于或者等于ie8版本
下面的代码是在非ie浏览器下运行的条件注释
<!--[if !ie]><!-->
您使用不是 internet explorer
<!--<![endif]-->
<!--[if ie 6]><!-->
您正在使用internet explorer version 6或者 一个非ie 浏览器
<!--<![endif]-->
复制代码 代码如下:

    <!doctype html> 
    <html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>div if条件实例</title> 
    </head> 
    <body> 
    你正在使用:  
    <!--[if ie 7]> 
    <h2>ie7</h2> 
    <![endif]--> 
    <!--[if ie 6]> 
    <h2>ie6</h2> 
    <![endif]--> 
    <!--[if ie 8]> 
    <h2>ie8</h2> 
    <![endif]--> 

    <!--[if ie 9]> 
    <h2>ie9</h2> 
    <![endif]--> 
    <br><br> 
    <strong>说明</strong>:如果你的浏览器版本为多少即会显示ie多少,针对ie6-ie9实验</body> 
    </html>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网