任务十三~浏览器兼容

2016-08-05  本文已影响131人  dengpan

一、如何调试 IE 浏览器?


二、什么是CSS hack?在 CSS 和 HTML里如何写 hack?在 CSS 中 ie6、ie7的 hack 方式?

.css_hack{    
   color:red; /* 所有浏览器 */  
   color:blue !important;/* 除了IE6外的所有浏览器 */  
   *color:black; /* IE6, IE7 */  
   +color:olive;/* IE6, IE7*/  
   color:gray\9; /* IE6, IE7, IE8, IE9, IE10 */  
   color:pink\0; /* IE8, IE9, IE10 */  
   color:orange\9\0;/*IE9, IE10*/  
   _color:green; /* 只在IE6中 */  
}
*html #selector {} /* 只对IE6生效 */
 *+html #selector {} /* 只对IE7生效 */
 @media screen\9 { .selector { property: value; } } /* 只对IE6、7生效 */ 
@media \0screen {body { background: red; }} /* 只对IE8生效 */ 
@media \0screen\,screen\9{body { background: blue; }} /* 只对IE6,IE7,IE8有效 */ 
@media screen\0 {body { background: green; }} /* 只对IE8,IE9,IE10生效 */ 
@media screen and (min-width:0\0) {body { background: gray; }} /* 只对IE9,IE10生效 */
@media screen and (-ms-high-contrast: active), 
(-ms-high-contrast: none) {body { background: orange; }} /*只对IE10有效*/

-css属性前缀法
div{ _color:orange; }

*html div {
     color: orange;
}

如图,在IE6中显示的效果图


IE6中的显示效果

在非IE6的浏览器中显示效果如下图


chrome浏览器
可以看出在chrome中条件注释的内容并未显示,更不用说为其设置的颜色!!

-css属性前缀法
div{ *color:orange; }

*+html div {
     color: orange;
}

如图,在IE7中显示的效果图

IE7中显示效果图
在非IE7的浏览器中显示效果如下图
chrome浏览器中显示效果
更多知识···

三、列举几种浏览器兼容问题?

.center{
                width: 300px;
                height: 300px;
                background: orange;
                opacity: 0.4;
            }

在IE7中显示效果如下


opacity在IE7中显示效果

而在现代浏览器中的显示效果如下


opacity在chrome中显示效果
要在IE7中兼容可以使用一下代码
filter:alpha(opacity=40);

此时在IE7中的显示效果如下图


opacity在IE7hack后效果图
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>exercise</title>
        <style>
            div{
                display: inline-block;
            }
            .box1{
                width: 300px;
                height: 300px;
                background: orange;
            }
            .box2{
                width: 300px;
                height: 300px;
                background: pink;
            }
            .box3{
                width: 300px;
                height: 300px;
                background: olive;
            }
        </style>
    </head>
    <body>
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
    </body>
</html>

在IE7中显示效果如下


inline-block在IE7中显示效果图

而在现代浏览器中的显示效果如下


inline-block在chrome中显示效果图
要在IE7中兼容可以使用一下代码
*display: inline;
*zoom:1;

此时在IE7中的显示效果如下图


inline-block在IE7hack后显示效果图
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>exercise</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        .box1{
            background: orange;
            width: 100px;
            height: 100px;
            float: left;
            margin: 25px;
        }
        .box2{
            background: olive;
            width: 100px;
            height: 100px;
            float: left;
            margin: 25px;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>
</html>

在IE6中显示效果如下


双外边距问题

而在现代浏览器中的显示效果


chrome无双外边距问题
要在IE6中兼容可以使用一下代码,如下
.box1{
            background: orange;
            width: 100px;
            height: 100px;
            float: left;
            margin: 25px;
            display: inline;
        }

此时在IE7中的显示效果如下图


解决浮动左外边距双倍问题后效果图

四、针对兼容、多浏览器覆盖有什么看法?渐进增强和优雅降级是什么意思?


五、reset.css和normalize.css分别是做什么的?为什么推荐使用 normalize.css?


六、IE盒模型和标准盒模型有什么区别? 怎样使IE6、IE7、IE8使用标准盒模型?box-sizing:border-box有什么作用?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>exercise</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        div{
            background: orange;
            width: 100px;
            height: 100px;
            border: 2px solid black;
            padding: 10px;
            margin: 25px;
        }
        .box{
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <div></div>
    <div class="box"></div>
</body>
</html>

效果图如下


设置box-sizing:border-box之后的效果图

七、操作1:virtualbox安装xp 虚拟机


八、操作2:在IE6、IE7、IE8中展示 盒模型inline-blockmax-width的区别

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>exercise</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        div{
            background: orange;
            width: 100px;
            height: 100px;
            border: 2px solid black;
            padding: 10px;
            margin: 25px;
        }
    </style>
</head>
<body>
    <div></div>
    <div></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>exercise</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        div{
            display: inline-block;
        }
        .box1{
            background: orange;
            width: 100px;
            height: 100px;
        }
        .box2{
            background: pink;
            width: 100px;
            height: 100px;
        }
        .box3{
            background: olive;
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>exercise</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        p{
            max-width: 200px;
            height: 200px;
            font-size: 20px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <p>this is a test this is a test this is a test this is a test 
this is a test this is a test this is a test this is a test 
this is a test this is a test this is a test this is a test 
this is a test this is a test this is a test this is a test 
this is a test this is a test this is a test this is a test 
this is a test this is a test this is a test this is a test </p>
</body>
</html>

版权声明:本教程版权归邓攀和饥人谷所有,转载须说明来源!!!!

上一篇 下一篇

猜你喜欢

热点阅读