原因:不同的浏览器对各个元素的margin,padding,borer,font等属性的定义各有不同,不同浏览器的显示效果可能不一样,为杜绝这种情况,通过css强制让所有元素的属性值都一样,这样浏览器显示就一致了,减少不兼容情况的发生,这个过程叫css的初始。
代码:
@charset "utf-8";
/* CSS Document */
*{
box-sizing:border-box;
-moz-box-sizing:border-box;/*兼容低版本的浏览器*/
-webkit-box-sizing:border-box;/*为了兼容低版本的web*/
color:#000;
}
body{
font-size:12px;
font-family:Arial,Verdana,Tahoma,"微软雅黑","黑体";
line-height:120%;
background:#fff;
margin:0;
overflow-x:hidden;/*溢出隐藏,去掉水平方向的,直接剪裁*/
}
p,h1,h2,h3,h4,h5,h6,ul,ol,dl,li,form,table{
margin:0;
padding:0;
}
a,img{
border:none;/*兼容ie浏览器*/
}
img{
vertical-align:middle;
border:0;
}
li{
list-style:none;
}
i,em{
font-style:normal;
}
a{
text-decoration:none;
color:#000000;
border:0;
}
a:link{
text-decoration:none;
color:#000000;
}
a:visited{
text-decoration:none;
color:#000000;
}
a:hover{
text-decoration:none;
color:#000000;
}
a:active{
text-decoration:none;
color:#000000;
}
.clearfix:before,.clearfix:after{
display:table;
content:"";
}
.clearfix:after{
clear:both;
}
.clearfix{
*zoom:1;
}/*兼容ie浏览器*/
table{border-collapse:collapse;}