CSS公共样式分享篇

样式:可以分为以下几类

  1. 格式化样式(默认样式的格式化【清除页面浏览器默认样式,保证初始样式在所有浏览器下一致】,字体默认设置)
  2. 公共组件样式(网站所有页面头部、底部样式都是一致的,而且很长时间不会有很大的改变,改变的大概就是产品、运营的经常需要添加、去掉某些入口的需求,要保证全站所有页面头部、页脚一次性生效【翻页、表单(输入框、按钮)等也是全站样式】)
  3. 当前页面样式(要保证一个页面一个独立样式。方便增删改查)

  • global.css | reset.css(格式化样式)
  • common.css(公共组件样式)
  • layout.css(当前页面样式)

其实global.css和common.css也可以合并到一个文件,毕竟格式化样式也就那么几十行代码,而且格式化样式、头部、底部样式每个页面都会用到。不要把什么东西都往组件样式里面塞,有写东西宁愿每个页面重复拷贝也不要塞到组件样式里面去。某一天,你会发现这个组件样式大得让你可怕,而且很多都是无用的。

/***********通用基本类1************/

/*格式化样式*/
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {margin:0;padding:0;}
table {border-collapse:collapse;border-spacing:0;}
fieldset,img {border:0}
address,caption,cite,code,dfn,em,strong,th,var {font-style:normal;font-weight:normal}
ol,ul {list-style:none}
caption,th {text-align:left}
h1,h2,h3,h4,h5,h6 {font-size:100%;font-weight:normal}
q:before,q:after {content:''}
abbr,acronym { border:0}

/*文字排版、颜色*/
.f12{font-size:12px}
.f13{font-size:13px}
.f14{font-size:14px}
.f16{font-size:16px}
.f20{font-size:20px}
.fb{font-weight:bold}
.fn{font-weight:normal}
.t2{text-indent:2em}
.red,a.red{color:#cc0031}
.darkblue,a.darkblue{color:#039}
.gray,a.gray{color:#878787}
.lh150{line-height:150%}
.lh180{line-height:180%}
.lh200{line-height:200%}
.unl{text-decoration:underline;}
.no_unl{text-decoration:none;}

/*定位*/
.tl{text-align:left}
.tc{text-align:center}
.tr{text-align:right}
.fl{float:left;display:inline}
.fr{float:right;display:inline}
.cb{clear:both}
.cl{clear:left}
.cr{clear:right}
.vm{vertical-align:middle}
.pr{position:relative}
.pa{position:absolute}
.abs-right{position:absolute;right:0}
.zoom{zoom:1}
.hidden{visibility:hidden}
.none{display:none}

/*长度高度*/
.w10{width:10px}
.w20{width:20px}
.w50{width:50px}
.w90{width:90px}
.w100{width:100px}
.w200{width:200px}
.w250{width:250px}
.w500{width:500px}
.w800{width:800px}
.w{width:100%}
.h50{height:50px}
.h80{height:80px}
.h100{height:100px}
.h200{height:200px}
.h{height:100%}

/*边距*/
.m10{margin:10px}
.m15{margin:15px}
.m30{margin:30px}
.mt5{margin-top:5px}
.mt10{margin-top:10px}
.mt15{margin-top:15px}
.mt50{margin-top:50px}
.mt100{margin-top:100px}
.mb5{margin-bottom:5px}
.mb10{margin-bottom:10px}
.mb15{margin-bottom:15px}
.mb100{margin-bottom:100px}
.ml5{margin-left:5px}
.ml10{margin-left:10px}
.ml15{margin-left:15px}
.ml20{margin-left:20px}
.ml30{margin-left:30px}
.ml50{margin-left:50px}
.ml100{margin-left:100px}
.mr5{margin-right:5px}
.mr10{margin-right:10px}
.mr15{margin-right:15px}
.mr50{margin-right:50px}
.mr100{margin-right:100px}
.p10{padding:10px;}
.p15{padding:15px;}
.p30{padding:30px;}
.pt5{padding-top:5px}
.pt10{padding-top:10px}
.pt15{padding-top:15px}
.pt20{padding-top:20px}
.pt30{padding-top:30px}
.pt50{padding-top:50px}
.pb5{padding-bottom:5px}
.pb100{padding-bottom:100px}
.pl5{padding-left:5px}
.pl10{padding-left:10px}
.pl50{padding-left:50px}
.pl100{padding-left:100px}
.pr5{padding-right:5px}
.pr10{padding-right:10px}
.pr15{padding-right:15px}
.pr100{padding-right:100px}

/***********通用基本类2************/

* {
padding: 0px;
margin: 0px;
text-align: left;
font-family:Arial, Verdana, Tahoma, "宋体", Helvetica, sans-serif;
line-height: 150%;
}

//==========设置body的基本样式===========

body {
font-size: 14px;
text-align: center;
color: #000000;
background-color: #DEEBF3;
background-image: url(../Images/body_bg.jpg);
background-repeat: repeat-x;
}

table {
border-collapse: collapse;
}
td {
padding: 3px;
}

//===========处理IE浏览器图片的默认border============
img {
border: none;
}
input {
padding: 1px;
vertical-align: middle;
line-height: normal;
}

//==========内容盒子设置基本样式=========
.main-box {
margin-right: auto;
margin-left: auto;
width: 960px;
clear: both;
zoom:1;
overflow:hidden;
background-color: #CCCCCC;
}

//===========单行超出隐藏(用省略号)==========

/*单行溢出,超出部分显示...或者截取。前提必须有宽度*/

.text-overflow-hidden {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}

//===========多行超出隐藏(省略号)=============

/*因使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;*/

.text-overflow-hidden {
display: -webkit-box;/* 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 */
-webkit-orient: vertical;/*必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 */
overflow: hidden;
text-overflow: ellipsis;
word-wrap: bleak-word;/*word-wrap 属性允许长单词或 URL 地址换行到下一行。*/
-webkit-line-clamp: 3;/*用来限制在一个块元素显示的文本的行数。*/
}

//跨浏览器兼容的方案

.text-overflow-hidden {
line-height: 1.2em;
height: 3.6em;/*超出n行省略号表示,那height必须为line-height的n倍*/
position: relative;
overflow: hidden;
}

/*用省略号背景图代表*/

.text-overflow-hidden:after {
content: '···';/*中文和英文这里的省略号有区别*/
font-weight: bold;/*超出n行省略号表示,那height必须为line-height的n倍*/
position: absolute;
bottom: 0;
right: 0;
background: url(../img/ellipsis.png) no-repeat;
padding: 0 20px;
}

/*======万能Float清除浮动1======*/

.clear:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}

.clear {display: inline-block;} /* for IE/Mac */

/*======万能Float清除浮动2======*/

.overflow-hidden{overflow:hidden;} /*控制背景溢出*/
.equal-height{margin-bottom:-32800px;padding-bottom:32800px;} /*控制高度足够小*/

/*======万能Float清除浮动3======*/

.clear
{
height:0px;
clear:both;
font-size:0px;
line-height:0px;
zoom: 1;
}

/*css定义超链接四个状态也有顺序的。*/

a:link, a:visited {
text-decoration: none;
color: #1F376D;
}
a:hover, a:active {
text-decoration: underline;
color: #BD0A01;
border: none;
}

无论什么知识总结,只有合适自己的,用起来才得心应手,雷厉风行。大家一起加油。

发布于 2017-03-28 16:27