0.2.0 • Published 8 years ago

postcss-sort-style-rules v0.2.0

Weekly downloads
133
License
MIT
Repository
github
Last release
8 years ago

PostCSS Sort Style Rules Build Status

PostCSS plugin to sort style rules according to selector specificity.

The order of CSS style rules only matters if two selector share same specificity. If two style rules have different specificity, changing their order will be safe and this will increase the chance that two style rules with same specificity become adjacent style rules. This is where postcss-merge-rules become useful.

If a style rule have a group of selectors, we can only rearrange the order if all selectors in one group have lower specificity than those in the other group.

.post {
  font-size: 1.5rem;
}
#title, div a {
  color: #69c;
}
.post {
  color: #ccc;
}
div {
  box-sizing: border-box;
}
div {
  box-sizing: border-box;
}
.post {
  font-size: 1.5rem;
}
#title, div a {
  color: #69c;
}
.post {
  color: #ccc;
}

Usage

postcss([ require('postcss-sort-style-rules') ])

See PostCSS docs for examples for your environment.