为什么要初始化CSS?

CSS初始化是指重设浏览器的样式。不同的浏览器默认的样式可能不尽相同,所以开发时的第一件事可能就是如何把它们统一。如果没对CSS初始化往往会出现浏览器之间的页面差异。每次新开发网站或新网页时候通过初始化CSS样式的属性,为我们将用到的CSS或html标签更加方便准确,使得我们开发网页内容时更加方便简洁,同时减少CSS代码量,节约网页下载时间。

CSS初始化示例代码

  1. /* css reset www.admin10000.com */
  2. 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:; padding:; }
  3. body { background:#fff; color:#555; font-size:14px; font-family: Verdana, Arial, Helvetica, sans-serif; }
  4. td,th,caption { font-size:14px; }
  5. h1, h2, h3, h4, h5, h6 { font-weight:normal; font-size:100%; }
  6. address, caption, cite, code, dfn, em, strong, th, var { font-style:normal; font-weight:normal;}
  7. a { color:#555; text-decoration:none; }
  8. a:hover { text-decoration:underline; }
  9. img { border:none; }
  10. ol,ul,li { list-style:none; }
  11. input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }
  12. table { border-collapse:collapse; }
  13. html {overflow-y: scroll;}
  14. /* css common */
  15. .clearfix:after {content: "."; display: block; height:; clear:both; visibility: hidden;}
  16. .clearfix { *zoom:; }

下面是定义的一些常用的css基础样式:

  1. /**
  2. * css初始化样式及自定义样式封装
  3. * @author
  4. * @date 2016-07-14
  5. */
  6.  
  7. @charset "UTF-8";
  8. * { margin:; padding:; }
  9. html { font-family: sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-text-size-adjust: none; -webkit-user-select: none; -moz-user-select: none; user-select: none; }
  10. html, body { font-family: Helvetica, Tahoma, Arial, "Microsoft YaHei", "微软雅黑", STXihei, "华文细黑", SimSun, "宋体", Heiti, "黑体", sans-serif; }
  11. article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
  12. ol, ul { list-style: none; }
  13. table { border-collapse: collapse; border-spacing:; }
  14. input, button, textarea { -webkit-appearance: none; }
  15.  
  16. /**
  17. * 定义预定义字体样式
  18. */
  19. ::-webkit-input-placeholder { color: #999; }
  20. :-moz-placeholder { color: #999; }
  21. ::-moz-placeholder { color: #999; }
  22. :-ms-input-placeholder { color: #999; }
  23. .placeholder { color: #999; }
  24.  
  25. /**
  26. * 清除浮动
  27. */
  28. .f-cb:after, .f-cbli li:after { display: block; clear: both; visibility: hidden; height:; overflow: hidden; content: "."; }
  29. .f-cb, .f-cbli li { zoom:; }
  30.  
  31. /**
  32. * 定义元素如何显示
  33. */
  34. .f-dib { display: inline-block; *display: inline; *zoom:; }
  35. .f-di { display: inline; }
  36. .f-dn { display: none; }
  37. .f-db { display: block; }
  38. .f-dt { display: table; }
  39. .f-dtr { display: table-row; }
  40. .f-dtc { display: table-cell; }
  41.  
  42. /**
  43. * 定义浮动
  44. */
  45. .f-fl { float: left; }
  46. .f-fr { float: right; }
  47. .f-fn { float: none; }
  48.  
  49. /**
  50. * 定义元素定位类型
  51. */
  52. .f-pr { position: relative; }
  53. .f-pa { position: absolute; }
  54. .f-pf { position: fixed; }
  55.  
  56. /**
  57. * 定义元素超出隐藏
  58. */
  59. .f-oh { overflow: hidden; }
  60.  
  61. /**
  62. * 定义字体相关样式
  63. */
  64. .f-tal { text-align: left; }
  65. .f-tac { text-align: center; }
  66. .f-tar { text-align: right; }
  67. .f-fwb { font-weight: bold; }
  68. .f-tdu, .f-tdu:hover { text-decoration: underline; }
  69. .f-tdn, .f-tdn:hover { text-decoration: none; }
  70.  
  71. /**
  72. * 溢出单行文本显示省略号
  73. */
  74. .f-toe { overflow: hidden; word-wrap: normal; white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; }
  75.  
  76. /**
  77. * 溢出文本强制换行
  78. */
  79. .f-pre { overflow: hidden; text-align: left; white-space: pre-wrap; word-wrap: break-word; word-break: break-all; }
  80.  
  81. /**
  82. * 定义鼠标悬浮样式
  83. */
  84. .f-csp { cursor: pointer; }
  85.  
  86. /**
  87. * 定义子元素垂直显示样式
  88. */
  89. .f-vat, .f-vata * { vertical-align: top; }
  90. .f-vab, .f-vaba * { vertical-align: bottom; }
  91. .f-vam, .f-vama * { vertical-align: middle; }
  92.  
  93. /**
  94. * 表格布局固定
  95. */
  96. .f-tlf { table-layout: fixed; }
  1. /**
  2. * 向右的小箭头
  3. */
  .icon-back::before {
    content: "";
    width: 12rpx;
    height: 12rpx;
    border: solid #848484;
    border-width: 1px 0 0 1px;
    transform: translate(-50%, -50%) rotate(135deg);
    position: absolute;
    right: -25rpx;
    top: 50%;
   }
  1. /**
  2. * 三角形
  3. */

  .triangle {
    width: 0;
    height: 0;
    border: 40px solid red;
    border-top-color: black;
    border-bottom: none;
    border-left-color: transparent;
    border-right-color: transparent;
  }

css初始化样式代码的更多相关文章

  1. CSS初始化样式

    为什么要初始化CSS? CSS初始化是指重设浏览器的样式.不同的浏览器默认的样式可能不尽相同,所以开发时的第一件事可能就是如何把它们统一.如果没对CSS初始化往往会出现浏览器之间的页面差异.每次新开发 ...

  2. CSS初始化示例代码

    CSS初始化示例代码 /* css reset www.admin10000.com */ body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code, ...

  3. 常用css初始化样式(淘宝)

    最简单粗暴的css初始化样式就是:*{padding:0:margin:0}(不推荐) 淘宝的样式初始化: body, h1, h2, h3, h4, h5, h6, hr, p, blockquot ...

  4. 一套常用的css初始化样式

    @charset "UTF-8"; /*css 初始化 */ html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, ...

  5. (转)雅虎工程师提供的css初始化示例代码

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...

  6. css 初始化样式

    @charset "UTF-8"; /* reset */ html,body,div,h1,h2,h3,h4,h5,h6,p,dl,dt,dd,ol,ul,li,fieldset ...

  7. 雅虎工程师提供的CSS初始化示例代码

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...

  8. 免费CSS鼠标样式代码大全

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] http://5211.91.tc/sb.htm

  9. CSS 初始化 代码

    腾讯QQ官网 样式初始化 ;} body{font:12px"宋体","Arial Narrow",HELVETICA;background:#fff;-web ...

随机推荐

  1. 【leetcode】Min Stack -- python版

    题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant ti ...

  2. Visual Studio 2015 前瞻 属性初始化赋值!

    通常我们建立属性的时候如果带初始化值的时候我们经常会这样处理. class MyClass { private string _name = "hello world!"; pub ...

  3. BZOJ 1031: [JSOI2007]字符加密Cipher 后缀数组

    1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6014  Solved: 2503[Submit ...

  4. 【CentOS】文件与目录管理

    一.文件与目录管理 0.cd--change directory cd -  返回上次的目录 cd ~ 返回到家目录 --对于root用户来说是/root,对于普通用户来说是/home/用户名 cd ...

  5. Hdu5093 Battle ships 二分图

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...

  6. Eclipse中快速删除空行

    1.在要编辑的文档中 "Ctrl"+"F",弹出搜索框: 2.在Find文本框中输入正则表达式:^\s*\n 3.勾选正则表达式选项: 4.Find和替换所有.

  7. jQuery学习之:Validation表单验证插件

    http://polaris.blog.51cto.com/1146394/258781/ 最近由于公司决定使用AJAX + Struts2来重构项目,让我仔细研究一下这两个,然后集中给同事讲讲,让每 ...

  8. Leetcode Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  9. 堆排序 Heapsort

    Prime + Heap 简直神了 时间优化好多,顺便就把Heapsort给撸了一发 具体看图 Heapsort利用完全二叉树+大(小)顶锥的结构每次将锥定元素和锥最末尾的元素交换 同时大(小)顶锥元 ...

  10. *HDU1142 最短路+记忆化dfs

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...