CSS书写规范以及命名规则

本文介绍了CSS的书写规范,包括缩写技巧如margin、padding和font,颜色代码的缩写,注释标准,以及命名规则。强调了避免小数点、减少id使用、不使用行内样式和链接伪类顺序的重要性。还提到了状态前缀的选择器应用,并提供了CSS初始化和常见的元素命名约定。
前言:很早就想些这篇文章了,但是自己一直懒,拖到现在才来总结
CSS书写顺序
1.位置属性
position
top
right
z-index
display
float
clear
2.大小属性
width
height
padding
margin
3.文字属性
font-size
line-height
letter-spacing
word-spacing
color
text-align
4.背景属性
background
border
box-shadow
5.其他属性
animation
transition

CSS缩写

margin—-上右下左
padding—上右下左
font—font : 是否斜体 字体粗细 字体大小/行高 字体样式
border—–宽,样式(solid,dashed,dotted),颜色

去掉小数点.

font-size: .8rem

颜色代码缩写

color: #fff;

注释规范

/*
@description: 这是什么文件的css
@author: xiaoD
update: xiaoD (2017-05-2 16:23)
*/

CSS命名规范

li-active ——- 规范
li_active ——-不规范
liActive ——–不规范

多个选择器换行

leftbar,
rightbar,
footer {
color: #fff;
}

0后面不要添加px

body,
html {
margin: 0;
padding: 0;
}

颜色尽量不要使用单词(十六进制转化为二进制速度更快)

减少id的使用

不要使用行内样式

链接书写顺序

a:link {

}
a:visited {

}
a:hover {

}
a: active: {

}

为选择器添加状态前缀

is-right {
color: white;
}
is-false {
color: red;
}

CSS初始化

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
 margin:0;
 padding:0;
 border:0;
 outline:0;
 font-size:100%;
 vertical-align:baseline;
 background:transparent;
}
body {
 line-height:1;
}
article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section { 
 display:block;
}
nav ul {
 list-style:none;
}
blockquote, q {
 quotes:none;
}
blockquote:before, blockquote:after,
q:before, q:after {
 content:'';
 content:none;
}
a {
 margin:0;
 padding:0;
 font-size:100%;
 vertical-align:baseline;
 background:transparent;
}
mark {
 background-color:#ff9;
 color:#000; 
 font-style:italic;
 font-weight:bold;
}
ins {
 background-color:#ff9;
 color:#000;
 text-decoration:none;
}
del {
 text-decoration: line-through;
}
abbr[title], dfn[title] {
 border-bottom:1px dotted;
 cursor:help;
}
table {
 border-collapse:collapse;
 border-spacing:0;
}
hr {
 display:block;
 height:1px;
 border:0; 
 border-top:1px solid #cccccc;
 margin:1em 0;
 padding:0;
}
input, select {
 vertical-align:middle;
}

CSS命名规则

header
content/container
footer
nav
sidebar
leftbar
rightbar
loginbar
logo
banner———————————-广告
hot—————————————热点
news
download
subnav———————————子导航栏
menu
search
friendlink
copyright
tags————————————-标签
list
title
tips
joinus
guide
service
register
status
vote
partnter——————————-合作伙伴

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值