饥人谷学习第12天
编码规范
一、命名技巧
1.语义化
语义化标签优先
基于功能命名、基于内容命名、基于表现命名
简略、明了、无后患
2.命名范例
命名用小写
命名用引号包裹
用中横线连接
命名体现功能,不涉及表现样式(颜色字体边框背景等)
常见命名1:
.wrap或.wrapper -- 用于外侧包裹
.container或 .ct -- 包裹容器
.header -- 用于头部
.body -- 页面 body
.footer -- 页面尾部
aside、sidebar -- 用于侧边栏
.content -- 和header footer 对应,用于主要内容
.navigation -- 导航元素
.pagination -- 分页
常见命名2:
.tabs > .tab -- tab 切换
.breadcrumbs -- 导航列表、面包屑
.dropdown -- 下拉菜单
.article -- 文章
.main -- 用于主体
.thumbnail -- 头像,小图像
.media -- 媒体资源
.panel -- 面板
.tooltip -- 鼠标放置上去的提示
.popup -- 鼠标点击弹出的提示
常见命名3:
.button、.btn -- 按钮
.ad -- 广告
.subnav -- 二级导航
.menu -- 菜单
.tag -- 标签
.message或者.notice -- 提示消息
.summary -- 摘要
.logo -- logo
.search -- 搜索框
.login -- 登录
常见命名4:
.register -- 注册
.username -- 用户名
.password -- 密码
.banner -- 广告条
.copyright -- 版权
.modal或者 .dialog -- 弹窗
常见命名5:
var 名字 = {
状态: [
'inverse',
'toggled',
'switched',
'original',
'initial',
'identified',
'disabled',
'loading',
'pending',
'syncing',
'default'
],
修饰: [
'dark',
'light',
'shaded',
'flat',
'ghost',
'maroon',
'pale',
'intense',
'twisted',
'narrow',
'wide',
'smooth',
'separate',
'clean',
'sharp',
'aligned'
],
元素: [
'pagination',
'modal',
'popup',
'article',
'story',
'flash',
'status',
'state',
'media',
'block',
'card',
'teaser',
'badge',
'label',
'sheet',
'poster',
'notice',
'record',
'entry',
'item',
'figure',
'square',
'module',
'bar',
'button',
'action',
'knob'
],
布局: [
'navigation',
'wrapper',
'inner',
'header',
'footer',
'aside',
'section',
'divider',
'content',
'container',
'panel',
'pane',
'construct',
'composition',
'spacing',
'frame'
]
}
二、CSS规范
书写规范
1.tab用两个空格表示 方法:在项目文件夹下新建 .editorconfig
文件
参考:Bootstrap 中的 .editorconfig 实例
2.css的:
后加个空格,{
前加个空格
3.每条声明后都加个分号
4.换行,不是都放到一行
5.颜色用小写,用缩写,#fff
6.小数不用写前缀,0.5s
->.5s
;0不用加单位
7.尽量缩写,margin:5px 10px 5px 10px
->margin: 5px 10px
网友评论