CSS经验分享:如何书写可维护的CSS代码

在前几天的文章中,我们讨论过书写高效CSS注意的七个方面。今天我们在52CSS.com和大家讨论如何书写可维护的CSS代码?

  一、在样式表开头添加一个注释块,用以描述这个样式表的创建日期、创建者、标记等备注信息。

div css xhtml xml Example Source Code Example Source Code [www.52css.com]
/* 
---------------------------------
Site: Site name 
Author: 52CSS.com
Updated: Date and time 
Updated by: Name 
--------------------------------- 
*/ 


  二、包括公用颜色标记 

div css xhtml xml Example Source Code Example Source Code [www.52css.com]
/* 
--------------------------------- 
COLORS
Body background: #def455
Container background: #fff 
Main Text: #333 
Links: #00600f 
Visited links: #098761 
Hover links: #aaf433 
H1, H2, H3: #960 
H4, H5, H6: #000 
---------------------------------
*/

 
  三、给ID和Class进行有意义的命名 

div css xhtml xml Example Source Code Example Source Code [www.52css.com]
不推荐的命名方式:
.green-box { ... } 
#big-text { ... } 

推荐使用的命名方式:
.pullquote {... }
#introduction {... } 


  四、将关联的样式规则进行整合 

div css xhtml xml Example Source Code Example Source Code [www.52css.com]
#header { ... } 
#header h1 { ... } 
#header h1 img { ... }
#header form { ... }
#header a#skip { ... }

#navigation { ... }
#navigation ul { ... }
#navigation ul li { ... }
#navigation ul li a { ... }
#navigation ul li a:hover { ... }

#content { ... }
#content h2 { ... }
#content p { ... }
#content ul { ... }
#content ul li { ... } 


  五、给样式添加清晰的注释 

div css xhtml xml Example Source Code Example Source Code [www.52css.com]
/*
--------------------------------- 
header styles 
--------------------------------- 
*/ 
#header { ... }
#header h1 { ... }
#header h1 img { ... }
#header form { ... } 

/* 
--------------------------------- 
navigation styles
--------------------------------- 
*/
#navigation { ... } 

转载于:https://www.cnblogs.com/fangxiandi/archive/2012/07/29/2614371.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值