css规范

一、CSS书写顺序

  • 1.位置属性(position, top, right,z-index, display, float等)
  • 2.大小(width, height, padding,margin)
  • 3.文字系列(font, line-height,letter-spacing, color- text-align等)
  • 4.背景(background, border等)
  • 5.其他(animation, transition等)

二、CSS书写规范

1.使用CSS缩写属性

CSS有些属性是可以缩写的,比如padding,margin,font等等,这样精简代码同时又能提高用户的阅读体验。

2.去掉小数点前的“0”

font-size:.8em

3.简写命名

4.16进制颜色代码缩写

color:#eba

三、常用的CSS命名规则

类别命名类别命名
header内容content
footer导航nav
侧栏sidebar栏目column
页面外围wrapperleft
rightcenter
登录条loginbar标志logo
广告banner页面主体main
热点hot新闻news
下载download子导航subnav
菜单menu子菜单submenu
搜索search友情链接friendlink
页脚footer版权copyright
滚动scroll内容content
标签tags文章列表list
提示信息msg小技巧tips
栏目标题title加入joinus
指南guide服务service
注册regsiter状态status
投票vote合作伙伴partner

ID的命名-页面结构

类别命名类别命名
容器container页面头部header
内容content/container页面主体main
页面底部footer导航nav
侧栏sidebar栏目column
页面外围控制整体布局宽度wrapperleft
rightcenter

ID的命名-导航

类别命名类别命名
导航nav主导航mainnav
子导航subnav顶导航topnav
边导航sidebar左导航leftsidebar
右导航rightsidebar菜单menu
子菜单submenu标题title
摘要summary

 ID的命名-功能

类别命名类别命名
标志logo广告banner
登陆login登录条loginbar
注册register搜索search
功能区shop标题title
加入joinus状态status
按钮btn滚动scroll
标签页tab文章列表list
提示信息msg当前current
小技巧tips图标icon
注释note指南guild
服务service热点hot
新闻news下载download
投票vote合作伙伴partner
友情链接link版权copyright

CSS样式表文件命名 

类别文件类别文件
主要master.css模块module.css
基本共用base.css布局layout.css
主题themes.css专栏columns.css
文字font.css表单forms.css
补丁mend.css打印print.css

四、命名空间规范

  • 布局:以 g 为命名空间,例如:.g-wrap 、.g-header、.g-content。
  • 状态:以 s 为命名空间,表示动态的、具有交互性质的状态,例如:.s-current、s-selected。
  • 工具:以 u 为命名空间,表示不耦合业务逻辑的、可复用的的工具,例如:u-clearfix、u-ellipsis。
  • 组件:以 m 为命名空间,表示可复用、移植的组件模块,例如:m-slider、m-dropMenu。
  • 钩子:以 j 为命名空间,表示特定给 JavaScript 调用的类名,例如:j-request、j-open。

公共:

/* Reset styles */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}

/* Global styles */
body {
    font-family: Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
}

/* Heading styles */
h1 {
    font-size: 2em;
    margin-bottom: 0.5em;
}

h2 {
    font-size: 1.5em;
    margin-bottom: 0.5em;
}

/* Paragraph styles */
p {
    margin-bottom: 1em;
}

/* Link styles */
a {
    color: #007bff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Button styles */
.button {
    display: inline-block;
    padding: 0.5em 1em;
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.button:hover {
    background-color: #0056b3;
}

网站相关:

/* Navigation styles */
.navbar {
    background-color: #333;
    padding: 1em;
}

.navbar ul {
    list-style-type: none;
}

.navbar li {
    display: inline-block;
    margin-right: 1em;
}

.navbar li:last-child {
    margin-right: 0;
}

.navbar a {
    color: #fff;
    text-decoration: none;
}

.navbar a:hover {
    text-decoration: underline;
}

/* Footer styles */
.footer {
    background-color: #f4f4f4;
    padding: 2em 0;
    text-align: center;
    font-size: 0.9em;
    color: #777;
}

/* Form styles */
.form-group {
    margin-bottom: 1.5em;
}

.form-group label {
    display: block;
    margin-bottom: 0.5em;
    font-weight: bold;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea {
    width: 100%;
    padding: 0.5em;
    font-size: 1em;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* Card styles */
.card {
    background-color: #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 1em;
    margin-bottom: 1.5em;
}

.card h3 {
    margin-bottom: 0.5em;
}

.card p {
    margin-bottom: 1em;
}

.card img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值