think-of-css

- 1 min

###css风格

OOCSS:Object Oriented Css
  1. Separate structure and skin
  2. Separate container and content
  3. Avoid the descendent selector (i.e. don’t use .sidebar h3)
  4. Avoid IDs as styling hooks
  5. Avoid attaching classes to elements in your stylesheet (i.e. don’t do div.header or h1.title)
SMACSS:Scalable and Modular Architecture for Css
  1. Base (element only selector)
  2. Layout (id selector + layout class)
  3. Module (class only selector + descendant selector)
  4. State (class selector)
  5. Theme (override below rules)
  6. Avoid tag selectors for common elements
  7. Use class names as the right-most selector
ACSS:Atomic CSS
  1. use atomic style
  2. don’t use concrete classname
BEM:Block Element Modifier
  1. use blockname-modulename
  2. no abstract classname

###会不会有更好的风格呢?

期望:
  1. 便于移植
  2. css文件尽量精简
  3. 可以应对频繁改动,而不致使复杂度增高
  4. 和html,js解耦
  5. 表示状态更清晰

###组件化css 听起来很像BEM?是有些相似,但BlockComponents的概念还是有所不同。举个例子:

	// BEM
	.user-block-hd {
		border:1px solid #333;
	}
	.user-block-button {
		background-color:#ccc;
	}
	.user-block-button-success {
		background-color:#eee;
	}
	
	// 组件化
	.user-block .hd {
		border:1px solid #333;
	}
	.user-block .button {
		background-color:#ccc;
	}
	.user-block .button[data-status="success"] {
		background-color:#eee;
	}

简单的来说:

###组件化css面临的问题:

解决方案:

rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora