css初始化样式代码
2016-11-29 11:14
423 查看
为什么要初始化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; }
相关文章推荐
- css页面通用样式初始化代码
- CSS样式初始化代码
- 用css alpha 滤镜 实现input file 样式美化代码
- css分页样式代码
- CSS 链接无焦点样式代码
- css-css初始化代码
- Flex中的CSS: (7)经过编译后CSS相关(样式)代码可能存在的场所
- CSS鼠标样式大全和鼠标指针代码 【来美化你的blog吧】
- JS判断不同分辨率调用不同的CSS样式文件实现思路及测试代码
- DIV+CSS通用样式布局实例代码
- CSS初始化代码
- 如何设置单词字体间距 css设置字体间距样式代码
- css分页样式代码
- css 分页样式代码(基于a或li)绿色与蓝色
- CSS初始化代码,重置浏览器中CSS默认属性(2)
- 同一html页面中不同链接的不同样式的css代码
- 用css alpha 滤镜 实现input file 样式美化代码
- 编写CSS代码时样式的命名规则
- 每个页面通用的CSS:global.css 对某些标签进行初始化样式设置 加些特定的margin值 等
- CSS文件设计初始化代码(css设计模板)