制定本规范的目的在于使咱们的CSS代码更加易于维护和重用,从而提高效率执行本规范时建议的流程
建议使用D(esign)C(oding)D(ebug)V(alidate)R(oundup),即DCDVR的流程。首先须要规划样式并分为共有样式和页面个性化样式,而后才开始编码,编码的同时进行Debug,Validate和代码片段的总结,而不是在全部模板都完成后才进行这三个步骤。 css
/** * @name: 组件名 * @overview: 组件介绍 * @require: 依赖的样式 * @author: 小鱼(sofish@163.com) */
.all-IE{property:value\9;} .gte-IE-8{property:value\0;} .lte-IE-7{*property:value;} .IE-7{+property:value;} .IE-6{_property:value;} .not-IE{property//:value;} @-moz-document url-prefix() { .firefox{property:value;} } @media all and (-webkit-min-device-pixel-ratio:0) { .webkit{property:value;} } @media all and (-webkit-min-device-pixel-ratio:10000),not all and (-webkit-min-device-pixel-ratio:0) { .opera{property:value;} } @media screen and (max-device-width: 480px) { .iphone-or-mobile-s-webkit{property:value;} }
.selector .child{property:value;} /* for ie-6 */ .selector > .child{property:value;} /* except ie-6 */
1.以下写法为例: html
/* 区域模块-1 */ .tech, .ued{ background:#f60 url(xxx/orange.png) no-repeat 0 0; } /* 区域模块-2 */ .tech{ width:950px; margin:0 auto; } .tech .wd{ width:620px; float:left; }
/* 区域模块-3 */ .ued{width:100%;padding:30px 50px;} .ued .visual{display:inline-block;font:700 normal 12px/1.5 arail;}
2.须要很是注意的点 web
font-weight:600; font-style:normal; font-size:12px; line-height:1.5; font-family:arial;
一般须要使用缩写规则的: express
padding: top right bottom left; <--> padding: top-bottom right+left; <--> padding: top left-right bottom; <--> padding: top-right-bottom-left; 如:padding:1px 2px 3px 4px; margin: 同上 color: red; color;#FFF; color:#ABCABC (颜色名>16进制写法;颜色名采用小写,16进制使用大写;写3位,仍是6位,自便) background: color imageUrl repeat attachment position; 如:background:#ddd url(wd.png) no-repeat scroll 10px 20px; border: size style color; 如: border:1px solid #ddd; font: weight variant style size/lineHeight family; 如 font:700 small-caps italic 12px/1.5 "Courier New"; font-weight 统一用 500 代替 normal, 用 700 代替 bold; list-style: type position image; 如:list-style: square inside url(wd.png); 不过,一般咱们要使用的是 list-style:none;
-moz-box-shadow: 1px 2px 3px #ddd; -webkit-box-shadow: 1px 2px 3px #ddd; box-shadow: 1px 2px 3px #ddd;
.selector{float:left;width:300px;height:200px;font-size:14px;color:#f36;}
2.有因才有果。
好比想使用”图片替换文字“技术,一般要使用的text-indent。若是咱们使用标签的是 span:<span>这个文字将被图片替换</span>,那么正确写法: 后端
.thepic{display:block;text-indent:-9999em;}
咱们应该是先将 span 变成”块级元素“,再将文字 indent。而不是先 indent 再变成块级的。
又如咱们,若是想让一个 span 使用 margin, 那么咱们应该这样写: 浏览器
span{display:block;margin-bottom:10px;}
而非margin-bottom先行,由于没有 display 以前,行内元素是没有 margin 的。 服务器
记住一句话:不管何时,都不要使用它。用 Javascript 吧。更优雅,更灵活。 框架
应该尽可能避免使用 AlphaImageLoader,能够适当在投影/发光/渐变/去色方面上使用。 iphone
/* global reset */ body{padding:0;margin:0;font.....} a{color:#07f;} a:hover{color:#555;}
须要注意的是,通常状况下,不要直接给标签写样式。而应该使用 class。像下面这种写法,并不合适: ide
h1{font-size:30px} h2{font-size:20px} h3{font-size:10px;}
若是有另一个 h2 也要使用 10px 的,而其余的都仍使用 20px 的,那可就很差办了。因此,推荐用这种方法:
/* global classes */ .text-size30{font-size:30px;} .text-size20{font-size:20px;} .text-size10{font-size:10px;} ... <h2 class="text-size20">... <h2 class="text-size10">...
有两点须要注意的,一是,注意代码重用的模块化;另外一是,注意 HTML 结构的模块化,而不是分块。
<div class="margin-test"> <div class="margin-2">i am 2.</div> </div> <div id="module-1" class="module"> <h3>TITLE</h3> <p class="module-item"> some text </p> </div> <div id="module-2" class="module"> < h3>TITLE</h3> <p class="module-item"> some text </p> </div> /* module, reuse style in module scrope*/ .module{} .module-status{} .module-item{} .module-status .module-1-item{} /* customize */ #module-1 .module-item{} #module-2 .module-item{}
<div id="module-1" class="module"> <h3>TITLE</h3> <p class="module-item"> some text </p> </div> <!-- #module .module -->
而不是这样写:
<h3>TITLE</h3> <!-- 第一块 --> <div id="module-1" class="module"> <p class="module-item"> some text </p> </div> <!-- 第二块 -->
1.Background Color
display: inline-block height: (除 auto 外任何值) width: (除 auto 外任何值) float: (left 或 right) position: absolute writing-mode: tb-rl zoom: (除 normal 外任意值)