简评: 浏览器兼容性题目经常让人头疼,以下是防止涌现这些题目的五个技能。
1. 前缀 CSS3 款式
假如您正在运用任何范例的当代 CSS 片断,比方框尺寸(box-sizing)或背景剪辑(background-clip),请确保运用恰当的前缀。
-moz- /* Firefox and other browsers using Mozilla's browser engine */
-webkit- /* Safari, Chrome and browsers using the Webkit engine */
-o- /* Opera */
-ms- /* Internet Explorer (but not always) */
2. 运用 reset
您能够运用 normalize.css,下面是我用的,来自 Genesis Framework Style Sheet。
html,body,div,span,applet,object,iframe,h1,h2,
h3,h4,h5,h6,p,blockquote,a,abbr,acronym,address,
big,cite,del,dfn,em,img,ins,kbd,q,s,samp,small,
strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,
dd,ol,ul,li,fieldset,form,label,legend,table,caption,
tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,
embed,figure,figcaption,footer,header,hgroup,input,menu,
nav,output,ruby,section,summary,time,mark,audio,video {
border: 0;
margin: 0;
padding: 0;
vertical-align: baseline;
}
3. 防止添补宽度
当你增加宽度为一个元素的添补时,它会变得更大。宽度和添补将被加在一起。
要处理这个题目,能够增加这个:
* { -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; }
4. 消灭 float
假如没有消灭,很轻易出题目。感兴趣的能够看看 Chris Coyier 的这篇文章。
能够运用此 CSS 代码片断来消灭:
.parent-selector:after {
content: "";
display: table;
clear: both;
}
假如你包装大部分的元素,一个异常简朴的要领是将它增加到你的 wrap 类中。
.wrap:after {
content: "";
display: table;
clear: both;
}
搞定!
5. 测试
建立您本身的跨浏览器基本架构或仅运用 Endtest。
假如你让这些东西成为一种习气,也许能够搞定九成的浏览器题目。
原文链接:
5 Tricks to Avoid Cross Browser Issues引荐浏览:
YouTube 上有哪些自学编程的优良频道
迎接关注:知乎专栏「极光日报」,天天为 Makers 导读三篇优良英文文章。