web开发中怎么样使css书写规范?

建站知识 2021-07-03 08:42www.168986.cn长沙网站建设
对于现在的web2.0,到底怎么书写css样式表,才算是最好的,最规范的!几乎没有什么明确的规定。在整个开发的项目中,只要写出一套最适合于团队开发的最好了。了很多的css样式书写范是大同小异的。需要不断的去归纳。

根据经验出以下几点规范,请大家参考一下
一.所有的CSS的尽量采用外部调用:这是我认为最重要的一点,因为这影响加载页面时的速度.
<LINK href="style/style.css" rel="stylesheet" type="text/css">
书写时重定义的最先,伪类,自定义(其中a:link a:visited a:hover a:actived 要按照顺序写)便于自己和他人阅读。
为了保证不同浏览器上字号保持一致,字号建议用点数pt和像素px来定义,pt一般使用中文宋体的9pt和11pt,px一般使用中文宋体12pt 和14.7px 这是经过优化的字号,黑体字或者宋体字加粗时,一般选用11pt和14.7px 的字号比较合适。

二. 样式名均以字母开头,后缀可包含字母、数字、下划线和中划线,样式名尽量采用通俗易懂的英文单词组成,如.img .body-bg #left_nav等(后附一些通用的命名标准);对于公用的自定义样式可适当加入模块标识或m标识,以免与独立模块样式产生冲突!
三.凡html内置标签及CSS属性名称均采用大写字母书写,而自定义样式名称及CSS属性值则均采用小写字母写书;如P{...} BODY{...} .p1{COLOR: red} .li_bg{MARGIN: 0px;} 等;
四.能采用缩写的样式属性尽量采用缩写形式,如margin,padding,border等;
(原则上-右-下-左 --> MARGIN: 1px 2px 3px 4px 上-(右左)-下 --> MARGIN: 1px 2px 3px
(上下)-(左右)--> MARGIN: 2px 4px 上右下左 --> MARGIN: 4px;
字体颜色类 #000000 --> #000 #00FFDD --> #0FD;
附缩写参考
There are a lot of CSS shorthand properties.
font
font: font-style font-variant font-weight font-size/line-height font-family;
margin
margin: margin- margin-right margin-bottom margin-left;
padding
padding: padding- padding-right padding-bottom padding-left;
border
border: border-width border-style border-color;
border-
border-: border--width border--style border--color;
border-right
border-right: border-right-width border-right-style border-right-color;
border-bottom
border-bottom: border-bottom-width border-bottom-style border-bottom-color;
border-left
border-left: border-left-width border-left-style border-left-color;
border-width
border-width: border--width border-right-width border-bottom-width border-left-width
background
background: background-color background-image background-repeat background-attachment background-position;
list-style
list-style: list-style-type list-style-position list-style-image;
outline
outline: outline-color outline-style outline-width;
五. 在书写样式的过程中,同一划分模块的样式尽量写在一起,并适当加入注释,以方便阅读和查找;如<-- Footer --><-- End Footer -->或者/ Footer / / End Footer /
六.样式抽象,我们可以把一些常用的样式抽象出来,做为一类样式;如COLOR: red FLOAT:left FONT-WEIGHT: bold等 这些属性我们可能要经常用到,我们是否需要为每个需要应用这个样式的元素都单独写上一个样式呢?答案是明确的不需要; 我们可以定义 .red{ COLOR:red } .fleft{FLOAT:left} 这样是不是要方便多了^_^

七. 效率规则:(css属性书写顺序)
1.显示样式
display/position/float/clear
2.自身样式
width/height/margin/padding/border/background
3.内容样式
line-height/text-align/font系列(font-size/font-weight)/color/text-decoration/vitical-align

八.css样式的命名:
对于css样式表的命名书写规范,请参考
关于更多的css书写规范,不止这些,还需要我们共同的来和学习,如果您有更好的见意,请留言!

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by