css初始化样式代码

为什么要初始化CSS?

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

CSS初始化示例代码

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

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

/**
 * css初始化样式及自定义样式封装
 * @author 
 * @date 2016-07-14
 */

@charset "UTF-8";
* { margin: 0; padding: 0; }
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; }
html, body { font-family: Helvetica, Tahoma, Arial, "Microsoft YaHei", "微软雅黑", STXihei, "华文细黑", SimSun, "宋体", Heiti, "黑体", sans-serif; }
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
ol, ul { list-style: none; }
table { border-collapse: collapse; border-spacing: 0; }
input, button, textarea { -webkit-appearance: none; }

/**
 * 定义预定义字体样式
 */
::-webkit-input-placeholder { color: #999; }
:-moz-placeholder { color: #999; }
::-moz-placeholder { color: #999; }
:-ms-input-placeholder { color: #999; }
.placeholder { color: #999; }

/**
 * 清除浮动
 */
.f-cb:after, .f-cbli li:after { display: block; clear: both; visibility: hidden; height: 0; overflow: hidden; content: "."; }
.f-cb, .f-cbli li { zoom: 1; }

/**
 * 定义元素如何显示
*/
.f-dib { display: inline-block; *display: inline; *zoom: 1; }
.f-di { display: inline; }
.f-dn { display: none; }
.f-db { display: block; }
.f-dt { display: table; }
.f-dtr { display: table-row; }
.f-dtc { display: table-cell; }

/**
 * 定义浮动
*/
.f-fl { float: left; }
.f-fr { float: right; }
.f-fn { float: none; }

/**
 * 定义元素定位类型
 */
.f-pr { position: relative; }
.f-pa { position: absolute; }
.f-pf { position: fixed; }

/**
 * 定义元素超出隐藏
 */
.f-oh { overflow: hidden; }

/**
 * 定义字体相关样式
 */
.f-tal { text-align: left; }
.f-tac { text-align: center; }
.f-tar { text-align: right; }
.f-fwb { font-weight: bold; }
.f-tdu, .f-tdu:hover { text-decoration: underline; }
.f-tdn, .f-tdn:hover { text-decoration: none; }

/**
 * 溢出单行文本显示省略号
 */
.f-toe { overflow: hidden; word-wrap: normal; white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; }

/**
 * 溢出文本强制换行
 */
.f-pre { overflow: hidden; text-align: left; white-space: pre-wrap; word-wrap: break-word; word-break: break-all; }

/**
 * 定义鼠标悬浮样式
 */
.f-csp { cursor: pointer; }

/**
 * 定义子元素垂直显示样式
 */
.f-vat, .f-vata * { vertical-align: top; }
.f-vab, .f-vaba * { vertical-align: bottom; }
.f-vam, .f-vama * { vertical-align: middle; }

/**
 * 表格布局固定
 */
.f-tlf { table-layout: fixed; }

/**
 * 向右的小箭头
 */
  .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%;
   }
/**
 * 三角形
 */

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

 

posted @ 2016-11-29 11:14  小猪ab  阅读(462)  评论(0编辑  收藏  举报