简评: 浏览器兼容性问题经常让人头疼,如下是避免出现这些问题的五个技巧。
若是您正在使用任何类型的现代 CSS 片断,例如框尺寸(box-sizing)或背景剪辑(background-clip),请确保使用适当的前缀。css
-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) */
您能够使用 normalize.css,下面是我用的,来自 Genesis Framework Style Sheet。html
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; }
当你添加宽度为一个元素的填充时,它会变得更大。宽度和填充将被加在一块儿。web
要解决这个问题,能够添加这个:编程
* { -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ -moz-box-sizing: border-box; /* Firefox, other Gecko */ box-sizing: border-box; }
若是没有清除,很容易出问题。感兴趣的能够看看 Chris Coyier 的这篇文章。canvas
能够使用此 CSS 代码片断来清除:浏览器
.parent-selector:after { content: ""; display: table; clear: both; }
若是你包装大部分的元素,一个很是简单的方法是将它添加到你的 wrap 类中。ruby
.wrap:after { content: ""; display: table; clear: both; }
搞定!架构
建立您本身的跨浏览器基础架构或仅使用 Endtest。app
若是你让这些东西成为一种习惯,大概能够搞定九成的浏览器问题。ide
原文连接: 5 Tricks to Avoid Cross Browser Issues
推荐阅读: YouTube 上有哪些自学编程的优质频道
欢迎关注:知乎专栏「极光日报」,天天为 Makers 导读三篇优质英文文章。