• 跨浏览器问题的五种解决方案


    简评: 浏览器兼容性问题常常让人头疼,以下是避免出现这些问题的五个技巧。

    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 导读三篇优质英文文章。

  • 相关阅读:
    python list添加元素的几种方法
    Python ---- list和dict遍历
    python 之 collections
    python list 中元素的统计与排序
    pandas dataframe 读取 xlsx 文件
    Python 缓存机制与 functools.lru_cache(zz)
    pip 使用
    python 中的异常处理
    python 时间日期处理
    python read txt file
  • 原文地址:https://www.cnblogs.com/jpush88/p/10974823.html
Copyright © 2020-2023  润新知