Wang's blog Wang's blog
首页
  • 前端文章

    • HTML教程
    • CSS
    • JavaScript
  • 前端框架

    • Vue
    • React
    • VuePress
    • Electron
  • 后端技术

    • Npm
    • Node
    • TypeScript
  • 编程规范

    • 规范
  • 我的笔记
  • Git
  • GitHub
  • VSCode
  • Mac工具
  • 数据库
  • Google
  • 服务器
  • Python爬虫
  • 前端教程
更多
收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Wang Mings

跟随大神,成为大神!
首页
  • 前端文章

    • HTML教程
    • CSS
    • JavaScript
  • 前端框架

    • Vue
    • React
    • VuePress
    • Electron
  • 后端技术

    • Npm
    • Node
    • TypeScript
  • 编程规范

    • 规范
  • 我的笔记
  • Git
  • GitHub
  • VSCode
  • Mac工具
  • 数据库
  • Google
  • 服务器
  • Python爬虫
  • 前端教程
更多
收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • CSS

  • Npm

  • Vue

  • HTML

  • Node

  • Yaml

  • React

  • 框架

  • 规范

    • 模板
    • JS规范
    • CSS规范
    • html规范
    • ESLint规范
    • readme文件
    • 命名规范
    • Git操作规范
    • 测试与发布
    • stylelint配置使用
    • Typescript错误忽略
  • Electron

  • JS演示

  • VuePress

  • JavaScript

  • TypeScript

  • 微信小程序

  • TypeScript-axios

  • 前端
  • 规范
wangmings
2022-07-19

CSS规范

# CSS 规范

  • 禁止内联 style
  • 嵌套层级不超过 4 级,尽量减少
  • 命名横杠 - 划分
  • 避免通配符和标签选择器
  • 编写顺序,由外到里
.class {
    display: flex;
    position: relative;
    left: 0;
    top: 0;
    margin: 10px;
    border: 1px solid #ccc;
    padding: 10px;
    width: 100px;
    height: 100px;
    color: #333333;
    font-size: 12px;
    font-weight: bold;
    background-color: #fff;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  • 有 0px 的删掉 px
margin: 0 10px;
1
  • margin 、 padding 合并缩写,同一元素不得有两个 margin / padding

  • 小数点前加 0

width: 0.5rem;

  • vue 中 style 标签使用 scoped 属性,如需改组件样式,可使用 ::v-deep
<style scoped lang="scss">
@import "./index.scss";
</style>
1
2
3
::v-depp .class{}
1
  • 颜色 16 进制用大写字母,6 位字符
color: #FFFFFF;
1
  • background-image 中填写 url 时,不需要携带引号
  • 空格
    • 属性值前
    • 选择器 >, +, ~ 前后
    • { 前
    • !important 的 ! 前
    • @else 前后
    • 属性值中的 , 后
    • 注释 / 后和 / 前
/* 注释 */
.class {
  color: red !important;
  background-color: rgba(0, 0, 0, .5);
}

.class1,
.class2 {
  /* ... */
}

.class > .class{
  /* ... */
}

.class {
  /* ... */
}

@if {
  /* ... */
} @else {
  /* ... */
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
编辑 (opens new window)
JS规范
html规范

← JS规范 html规范→

最近更新
01
theme-vdoing-blog博客静态编译问题
09-16
02
搜索引擎
07-19
03
友情链接
07-19
更多文章>
Theme by Vdoing | Copyright © 2019-2022 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式