经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » HTML5 » 查看文章
清除浏览器默认样式
来源:cnblogs  作者:C_XingM  时间:2019/7/17 10:51:03  对本文有异议

清除浏览器默认样式的原因

一、 某些标签的默认样式不符合我们的设计要求。比如说a标签,默认它是有一条下划线,并且字体颜色也让人觉得很难看,所以我们需要清除它默认的样式,同时根据要求给它重新添加自定义样式。如图是a标签的默认样式。

二、各浏览器默认的样式各不同,所以会影响到我们的开发,因为在每次开发之前应该先对浏览器的默认样式进行一次清除,让每个浏览器保持一致的初始化样式。清除默认样式可以提高代码浏览器间的兼容性,同一个标签用在不同的浏览器中,默认样式可能不一样,比如说,行高在某个浏览器中是1,在另一个浏览器中可能是1.1,这样在布局的时候会得到两种不同的效果,从而带来兼容性问题。因此,统一清除标签的默认样式,再统一重新添加新的样式,就能避免这种问题。

  1. 1.页边距
  2. IE默认为10px,通过bodymargin属性设置
  3. FF默认为8px,通过bodypadding属性设置
  4. 要清除页边距一定要清除这两个属性值
  5. body {
  6. margin:0;
  7. padding:0;
  8. }
  9. 2.段间距
  10. IE默认为19px,通过pmargin-top属性设置
  11. FF默认为1.12em,通过pmargin-bottom属性设
  12. p默认为块状显示,要清除段间距,一般可以设置
  13. p {
  14. margin-top:0;
  15. margin-bottom:0;
  16. }
  17. 3.标题样式
  18. h1~h6默认加粗显示:font-weight:bold;。
  19. 默认大小请参上表
  20. 还有是这样的写的
  21. h1 {font-size:xx-large;}
  22. h2 {font-size:x-large;}
  23. h3 {font-size:large;}
  24. h4 {font-size:medium;}
  25. h5 {font-size:small;}
  26. h6 {font-size:x-small;}
  27. 个大浏览器默认字体大小为16px,即等于mediumh1~h6元素默认以块状显示字体显示为粗体,
  28. 要清除标题样式,一般可以设置
  29. hx {
  30. font-weight:normal;
  31. font-size:value;
  32. }
  33. 4.列表样式
  34. IE默认为40px,通过ulolmargin属性设置
  35. FF默认为40px,通过ulolpadding属性设置
  36. dl无缩进,但起内部的说明元素dd默认缩进40px,而名称元素dt没有缩进。
  37. 要清除列表样式,一般可以设置
  38. ul, ol, dd {
  39. list-style-type:none;/*清楚列表样式符*/
  40. margin-left:0;/*清楚IE左缩进*/
  41. padding-left:0;/*清楚非IE左缩进*/
  42. }
  43. 5.元素居中
  44. IE默认为text-align:center;
  45. FF默认为margin-left:auto;margin-right:auto;
  46. 6.超链接样式
  47. a 样式默认带有下划线,显示颜色为蓝色,被访问过的超链接变紫色,要清除链接样式,一般可以设置
  48. a {
  49. text-decoration:none;
  50. color:#colorname;
  51. }
  52. 7 鼠标样式
  53. IE默认为cursor:hand;
  54. FF默认为cursor:pointer;。该声明在IE中也有效
  55. 8 图片链接样式
  56. IE默认为紫色2px的边框线
  57. FF默认为蓝色2px的边框线
  58. 要清除图片链接样式,一般可以设置
  59. img {
  60. border:0;vertical-aligntop
  61. }
  62.  
浏览器默认样式
  1. html, address,blockquote,body, dd, div,dl, dt, fieldset, form,frame, frameset,h1, h2, h3, h4,h5, h6, noframes,ol, p, ul, center,dir, hr, menu, pre { display: block }/*以上列表元素默认状态下一块状显示,未显示的将以内联元素显示,该列表针对HTML4版本,部分元素在XHTML1中将废弃*/
  2. li { display: list-item }/*默认以列表显示*/
  3. head { display: none }/*默认不显示*/
  4. table { display: table }/*默认为表格显示*/
  5. tr { display: table-row }/*默认为表格行显示*/
  6. thead { display: table-header-group }/*默认为表格头部分组显示*/
  7. tbody { display: table-row-group }/*默认为表格行分组显示*/
  8. tfoot { display: table-footer-group }/*默认为表格底部分组显示*/
  9. col { display: table-column }/*默认为表格列显示*/
  10. colgroup { display: table-column-group }/*默认为表格列分组显示*/
  11. td, th { display: table-cell; }/*默认为单元格显示*/
  12. caption { display: table-caption }/*默认为表格标题显示*/
  13. th { font-weight: bolder; text-align: center }/*默认为表格标题显示,呈现加粗居中状态*/
  14. caption { text-align: center }/*默认为表格标题显示,呈现居中状态*/
  15. body { margin: 8px; line-height: 1.12 }
  16. h1 { font-size: 2em; margin: .67em 0 }
  17. h2 { font-size: 1.5em; margin: .75em 0 }
  18. h3 { font-size: 1.17em; margin: .83em 0 }
  19. h4, p, blockquote, ul, fieldset, form, ol, dl, dir, menu { margin: 1.12em 0 }
  20. h5 { font-size: .83em; margin: 1.5em 0 }
  21. h6 { font-size: .75em; margin: 1.67em 0 }
  22. h1, h2, h3, h4, h5, h6, b,strong { font-weight: bolder }
  23. blockquote { margin-left: 40px; margin-right: 40px }
  24. i, cite, em,var, address { font-style: italic }
  25. pre, tt, code, kbd, samp { font-family: monospace }
  26. pre { white-space: pre }
  27. button, textarea, input, object, select { display:inline-block; }
  28. big { font-size: 1.17em }
  29. small, sub, sup { font-size: .83em }
  30. sub { vertical-align: sub }/*定义sub元素默认为下标显示*/
  31. sup { vertical-align: super }/*定义sub元素默认为上标显示*/
  32. table { border-spacing: 2px; }
  33. thead, tbody, tfoot { vertical-align: middle }/*定义表头、主体表、表脚元素默认为垂直对齐*/
  34. td, th { vertical-align: inherit }/*定义单元格、列标题默认为垂直对齐默认为继承*/
  35. s, strike, del { text-decoration: line-through }/*定义这些元素默认为删除线显示*/
  36. hr { border: 1px inset }/*定义分割线默认为1px宽的3D凹边效果*/
  37. ol, ul, dir, menu, dd { margin-left: 40px }
  38. ol { list-style-type: decimal }
  39. ol ul, ul ol, ul ul, ol ol { margin-top: 0; margin-bottom: 0 }
  40. u, ins { text-decoration: underline }
  41. br:before { content: ""A" }/*定义换行元素的伪对象内容样式*/
  42. :before, :after { white-space: pre-line }/*定义伪对象空格字符的默认样式*/
  43. center { text-align: center }
  44. abbr, acronym { font-variant: small-caps; letter-spacing: 0.1em }
  45. :link, :visited { text-decoration: underline }
  46. :focus { outline: thin dotted invert }
  47. /* Begin bidirectionality settings (do not change) */
  48. BDO[DIR="ltr"] { direction: ltr; unicode-bidi: bidi-override }/*定义BDO元素当其属性为DIR="ltr"时的默认文本读写显示顺序*/
  49. BDO[DIR="rtl"] { direction: rtl; unicode-bidi: bidi-override }/*定义BDO元素当其属性为DIR="rtl"时的默认文本读写显示顺序*/
  50. *[DIR="ltr"] { direction: ltr; unicode-bidi: embed }/*定义任何元素当其属性为DIR="ltr"时的默认文本读写显示顺序*/
  51. *[DIR="rtl"] { direction: rtl; unicode-bidi: embed }/*定义任何元素当其属性为DIR="rtl"时的默认文本读写显示顺序*/
  52. @media print { /*定义标题和列表默认的打印样式*/
  53. h1 { page-break-before: always }
  54. h1, h2, h3, h4, h5, h6 { page-break-after: avoid }
  55. ul, ol, dl { page-break-before: avoid }
  56. }
HTML默认样式

reset.css,用于清除浏览器差异的默认样式【结合我自己的备份和网上找的共三份,任选一份,我推荐第一份这是我自己日常在用的】

  1. body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { margin:0; padding:0; }
  2. body { background:#fff; color:#555; font-size:14px; font-family: "Microsoft YaHei", Arial, Helvetica, sans-serif; }
  3. td,th,caption { font-size:14px; }
  4. h1, h2, h3, h4, h5, h6 { font-weight:normal; font-size:100%; }
  5. address, caption, cite, code, dfn, em, strong, th, var { font-style:normal; font-weight:normal;}
  6. a { text-decoration:none; }
  7. a:hover { text-decoration:none; }
  8. img { border:none; }
  9. ol,ul,li { list-style:none; }
  10. input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }
  11. table { border-collapse:collapse; }
  12. html {overflow-y: scroll;}
  13. .clearfix::after {content: "."; display: block; height:0; clear:both; visibility: hidden;}
  14. .clearfix { *zoom:1; }
reset.css-1
  1. html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,caption,th,td,form,fieldset,legend,input,button,textarea,menu{margin:0;padding:0;}
  2. header,footer,section,article,aside,nav,hgroup,address,figure,figcaption,menu,details{display:block;}
  3. table{border-collapse:collapse;border-spacing:0;}
  4. caption,th{text-align:left;font-weight:normal;}
  5. html,body,fieldset,img,iframe,abbr{border:0;}
  6. i,cite,em,var,address,dfn{font-style:normal;}
  7. [hidefocus],summary{outline:0;}
  8. li{list-style:none;}
  9. h1,h2,h3,h4,h5,h6,small{font-size:100%;}
  10. sup,sub{font-size:83%;}
  11. pre,code,kbd,samp{font-family:inherit;}
  12. q:before,q:after{content:none;}
  13. textarea{overflow:auto;resize:none;}
  14. label,summary{cursor:default;}
  15. a,button{cursor:pointer;}
  16. h1,h2,h3,h4,h5,h6,em,strong,b{font-weight:bold;}
  17. del,ins,u,s,a,a:hover{text-decoration:none;}
  18. body,textarea,input,button,select,keygen,legend{font:12px/1.14 arial,\5b8b\4f53;color:#333;outline:0;}
  19. body{background:#fff;}
  20. a,a:hover{color:#333;}
reset.css-2
  1. html, body, div, span, applet, object, iframe,
  2. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  3. a, abbr, acronym, address, big, cite, code,
  4. del, dfn, em, img, ins, kbd, q, s, samp,
  5. small, strike, strong, sub, sup, tt, var,
  6. b, u, i, center,
  7. dl, dt, dd, ol, ul, li,
  8. fieldset, form, label, legend,
  9. table, caption, tbody, tfoot, thead, tr, th, td,
  10. article, aside, canvas, details, embed,
  11. figure, figcaption, footer, header, hgroup,
  12. menu, nav, output, ruby, section, summary,
  13. time, mark, audio, video {
  14. margin: 0;
  15. padding: 0;
  16. border: 0;
  17. font-size: 100%;
  18. font: inherit;
  19. vertical-align: baseline;
  20. }
  21. /* HTML5 display-role reset for older browsers */
  22. article, aside, details, figcaption, figure,
  23. footer, header, hgroup, menu, nav, section {
  24. display: block;
  25. }
  26. body {
  27. line-height: 1;
  28. }
  29. ol, ul {
  30. list-style: none;
  31. }
  32. blockquote, q {
  33. quotes: none;
  34. }
  35. blockquote:before, blockquote:after,
  36. q:before, q:after {
  37. content: '';
  38. content: none;
  39. }
  40. table {
  41. border-collapse: collapse;
  42. border-spacing: 0;
  43. }
reset.css-3

 

原文链接:http://www.cnblogs.com/Caixingmin/p/11196614.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号