程序员

CSS规范

2020-05-22  本文已影响0人  ale0512

CSS风格指南

基本原则

命名规范

padding
margin
font
background
border
border-radius

CSS代码格式

由于定位(positioning)可以从正常的文档流中移除元素,并且还能覆盖盒模型(box model)相关的样式,因此排在首位。盒模型决定了组件的尺寸和位置,因此排在第二位。

.declaration-order {
  /* Positioning */
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 100;

  /* Box-model */
  display: block;
  float: right;
  width: 100px;
  height: 100px;

  /* Typography */
  font: normal 13px "Helvetica Neue", sans-serif;
  line-height: 1.5;
  color: #333;
  text-align: center;

  /* Visual */
  background-color: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 3px;

  /* Misc */
  opacity: 1;
}

模块化

例如:

 <div class="ty-box">
   <h2 class="ty-box-hd">About the Site</h2>
   <p class="ty-box-bd">This is my blog </p>
</div>

以上代码中ty-box-hd{命名空间}-{模块名}-{子模块}

上一篇 下一篇

猜你喜欢

热点阅读