侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

目前比较全的CSS reset重设方法总结

前端  /  管理员 发布于 7年前   177

在当今网页设计/开发实践中,使用CSS来为语义化的(X)HTML标记添加样式风格是重要的关键。在设计师们的梦想中都存在着这样的一个完美世界:所有的浏览器都能够理解和适用多有CSS规则,并且呈现相同的视觉效果(没有兼容性问题)。但是,我们并没有生活在这个完美的世界,现实中发生的失窃却总是恰恰相反,很多CSS样式在不同的浏览器中有着不同的解释和呈现。

  当今流行的浏览器(如:Firefox、Opera、Internet Explorer、Chrome、Safari等等)中,有一些都是以自己的方式去理解CSS规范,这就会导致有的浏览器对CSS的解释与设计师的CSS定义初衷相冲突,使得网页的样子在某些浏览器下能正确按照设计师的想法显示,但有些浏览器却并没有按照设计师想要的样子显示出来,这就导致浏览器的兼容性问题。更糟的是,有的浏览器完全无视CSS的一些声明和属性。

  正因为上述冲突和问题依然存在于这个”不完美的世界”,所以一些设计师想到了一种避免浏览器兼容性问题的方法,那就是CSS Reset,什么是CSS Reset?我们可以把它叫做CSS重设,也有人叫做CSS复位、默认CSS、CSS重置等。CSS重设就是由于各种浏览器解释CSS样式的初始值有所不同,导致设计师在没有定义某个CSS属性时,不同的浏览器会按照自己的默认值来为没有定义的样式赋值,所以我们要先定义好一些CSS样式,来让所有浏览器都按照同样的规则解释CSS,这样就能避免发生这种问题。

一.最简化的CSS Reset(重设) :

CSS Code复制内容到剪贴板
  1. * {   
  2.       padding: 0;   
  3.       margin: 0;   
  4. }  

  这是最普遍最简单的CSS重设,将所有元素的padding和margin值都设为0,可以避免一些浏览器在理解这两个属性默认值上的”分歧”。

CSS Code复制内容到剪贴板
  1. * {   
  2.        padding: 0;   
  3.        margin: 0;   
  4.        border: 0;   
  5. }  

  这是在上一个重设的基础上添加了对border属性的重设,初始值为0的确能避免一些问题。

CSS Code复制内容到剪贴板
  1. * {   
  2.        outline: 0;   
  3.        padding: 0;   
  4.        margin: 0;   
  5.        border: 0;   
  6. }  

  在前两个的基础上添加了outline属性的重设,防止一些冲突。


二.浓缩实用型CSS Reset(重设):

CSS Code复制内容到剪贴板
  1. * {   
  2.        vertical-align: baselinebaseline;   
  3.        font-weight: inherit;    
  4.        font-family: inherit;    
  5.        font-style: inherit;   
  6.        font-size: 100%;   
  7.        outline: 0;   
  8.        padding: 0;   
  9.        margin: 0;   
  10.        border: 0;   
  11. }  

  该CSS重设方法出自Perishable Press,这是他常用的方法。

三.Poor Man 的CSS Reset:

CSS Code复制内容到剪贴板
  1. html, body {    
  2.        padding: 0;    
  3.        margin: 0;    
  4. }   
  5. html {   
  6.        font-size:1em;   
  7. }    
  8. body {   
  9.        font-size:100%;   
  10. }    
  11. a img, :link img, :visited img {   
  12.        border:0px;   
  13. }   

  这个重设方法将html和body下元素的padding和margin都设为0,并分别为html标签和body标签下的所有元素设置了初始的字体大小,最重要的是把有链接的图片的默认边框去掉了。

四.Siolon’s Global Reset

CSS Code复制内容到剪贴板
  1. * {    
  2.     vertical-align: baselinebaseline;   
  3.     font-family: inherit;   
  4.     fo   
  5.   
  6. nt-style: inherit;   
  7.     font-size: 100%;   
  8.     border: none;   
  9.     padding: 0;   
  10.     margin: 0;    
  11. }   
  12. body {   
  13.     padding: 5px;   
  14. }    
  15. h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {   
  16.     margin: 20px 0;   
  17. }   
  18. li, dd, blockquote {    
  19.     margin-left: 40px;   
  20. }    
  21. table {    
  22.     border-collapse: collapse;    
  23.     border-spacing: 0;    
  24. }  

五.Shaun Inman’s Global Reset

CSS Code复制内容到剪贴板
  1. body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, table, th, td, embed, object {   
  2.     padding: 0;   
  3.     margin: 0;    
  4. }   
  5. table {   
  6.     border-collapse: collapse;   
  7.     border-spacing: 0;   
  8. }   
  9.     fieldset, img, abbr {   
  10.     border: 0;   
  11. }   
  12. address, caption, cite, code, dfn, em,    
  13. h1, h2, h3, h4, h5, h6, strong, th, var {   
  14.     font-weight: normal;   
  15.     font-style: normal;   
  16. }   
  17. ul {   
  18.     list-style: none;   
  19. }   
  20. caption, th {   
  21.     text-align: left;   
  22. }   
  23. h1, h2, h3, h4, h5, h6 {   
  24.     font-size: 1.0em;   
  25. }   
  26. q:before, q:after {   
  27.     content: ”;   
  28. }   
  29. a, ins {   
  30.     text-decoration: none;   
  31. }  

六.Yahoo(YUI) CSS Reset:

CSS Code复制内容到剪贴板
  1. body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,    
  2. form,fieldset,input,textarea,p,blockquote,th,td {    
  3.     padding: 0;    
  4.     margin: 0;    
  5. }    
  6. table {    
  7.     border-collapse: collapse;    
  8.     border-spacing: 0;    
  9. }    
  10. fieldset,img {    
  11.     border: 0;    
  12. }    
  13. address,caption,cite,code,dfn,em,strong,th,var {    
  14.     font-weight: normal;    
  15.     font-style: normal;    
  16. }    
  17. ol,ul {    
  18.     list-style: none;    
  19. }    
  20. caption,th {    
  21.     text-align: left;    
  22. }    
  23. h1,h2,h3,h4,h5,h6 {    
  24.     font-weight: normal;    
  25.     font-size: 100%;    
  26. }    
  27. q:before,q:after {    
  28.     content:”;    
  29. }    
  30. abbr,acronym {    
  31.     border: 0;    
  32. }  

七.Eric Meyer’s CSS Reset

CSS Code复制内容到剪贴板
  1. html, body, div, span, applet, object, iframe, table, caption,    
  2. tbody, tfoot, thead, tr, th, td, del, dfn, em, font, img, ins,    
  3. kbd, q, s, samp, small, strike, strong, sub, sup, tt, var,    
  4. h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr,    
  5. acronym, address, big, cite, code, dl, dt, dd, ol, ul, li,    
  6. fieldset, form, label, legend {    
  7.     vertical-align: baselinebaseline;    
  8.     font-family: inherit;    
  9.     font-weight: inherit;    
  10.     font-style: inherit;    
  11.     font-size: 100%;    
  12.     outline: 0;    
  13.     padding: 0;    
  14.     margin: 0;    
  15.     border: 0;    
  16. }    
  17. :focus {    
  18.     outline: 0;    
  19. }    
  20. body {    
  21.     background: white;    
  22.     line-height: 1;    
  23.     color: black;    
  24. }    
  25. ol, ul {    
  26.     list-style: none;    
  27. }    
  28. table {    
  29.     border-collapse: separate;    
  30.     border-spacing: 0;    
  31. }    
  32. caption, th, td {    
  33.     font-weight: normal;    
  34.     text-align: left;    
  35. }    
  36. blockquote:before, blockquote:after, q:before, q:after {    
  37.     content: “”;    
  38. }    
  39. blockquote, q {    
  40.     quotes: “” “”;    
  41. }  

八.Condensed Meyer Reset:

CSS Code复制内容到剪贴板
  1. body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6,    
  2. pre, form, fieldset, input, textarea, p, blockquote, th, td {    
  3.     padding: 0;   
  4.     margin: 0;   
  5. }   
  6.     fieldset, img {    
  7.     border: 0;   
  8. }   
  9. table {   
  10.     border-collapse: collapse;   
  11.     border-spacing: 0;   
  12. }   
  13. ol, ul {   
  14.     list-style: none;   
  15. }   
  16. address, caption, cite, code, dfn, em, strong, th, var {   
  17.     font-weight: normal;   
  18.     font-style: normal;   
  19. }   
  20. caption, th {   
  21.     text-align: left;   
  22. }   
  23. h1, h2, h3, h4, h5, h6 {   
  24.     font-weight: normal;   
  25.     font-size: 100%;   
  26. }   
  27. q:before, q:after {   
  28.     content: ”;   
  29. }   
  30. abbr, acronym {    
  31.     border: 0;   
  32. }  

九.Ateneu Popular CSS Reset

CSS Code复制内容到剪贴板
  1. html, body, div, span, applet, object, iframe, h1, h2, h3,    
  2. h4, h5, h6, p, blockquote, pre, a, abbr, acronym,    
  3. address, big, cite, code, del, dfn, em, font, img, ins,    
  4. kbd, q, s, samp, small, strike, strong, sub, sup, tt,    
  5. var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend,    
  6. table, caption, tbody, tfoot, thead, tr, th, td {    
  7.     margin: 0;    
  8.     padding: 0;    
  9.     border: 0;    
  10.     outline: 0;    
  11.     font-weight: inherit;    
  12.     font-style: inherit;    
  13.     font-size: 100%;    
  14.     font-family: inherit;    
  15.     vertical-align: baselinebaseline;    
  16. }    
  17. :focus {   
  18.     outline: 0;   
  19. }    
  20. a, a:link, a:visited, a:hover, a:active{   
  21.     text-decoration:none  
  22. }    
  23. table {   
  24.     border-collapse: separate;   
  25.     border-spacing: 0;   
  26. }    
  27. th, td {   
  28.     text-align: left;   
  29.     font-weight: normal;   
  30. }    
  31. img, iframe {   
  32.     border: none;   
  33.     text-decoration:none;   
  34. }    
  35. ol, ul {   
  36.     list-style: none;   
  37. }    
  38. input, textarea, select, button {   
  39.     font-size: 100%;   
  40.     font-family: inherit;   
  41. }    
  42. select {   
  43.     margin: inherit;   
  44. }    
  45. hr {   
  46.     margin: 0;   
  47.     padding: 0;   
  48.     border: 0;   
  49.     color: #000;   
  50.     background-color: #000;   
  51.     height: 1px  
  52. }  

十.Chris Poteet’s Reset CSS

CSS Code复制内容到剪贴板

  • 上一条:
    CSS计数器(序列数字字符自动递增)详解
    下一条:
    Discuzx系统 CSS 编码规范、CSS属性书写顺序
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 使用 Alpine.js 排序插件对元素进行排序(0个评论)
    • 在js中使用jszip + file-saver实现批量下载OSS文件功能示例(0个评论)
    • 在vue中实现父页面按钮显示子组件中的el-dialog效果(0个评论)
    • 使用mock-server实现模拟接口对接流程步骤(0个评论)
    • vue项目打包程序实现把项目打包成一个exe可执行程序(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-03
    • 2018-04
    • 2018-05
    • 2018-06
    • 2018-09
    • 2018-11
    • 2018-12
    • 2019-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客