Skip to content

Instantly share code, notes, and snippets.

@klihelp
Forked from daneden/Property Order.md
Created December 1, 2015 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klihelp/547a96698042e64a9363 to your computer and use it in GitHub Desktop.
Save klihelp/547a96698042e64a9363 to your computer and use it in GitHub Desktop.

Regarding property ordering, I have to disagree that alphabetical is the sensible route. My ordering might seem strange, but the properties are grouped and ordered by relation to one another. Given the following example:

.element {
  box-sizing: content-box;
  color: blue;
  display: block;
  font-family: "Open Sans", sans-serif;
  font-size: 13px;
  font-style: italic;
  font-weight: 400;
  padding: 30px;
  width: 100px;
}

You can imagine the author’s expectation would be for the .element to render with a width of 100px, but because box-sizing: content-box is present, the width is actually calculated as 100px plus the 30px padding, totaling 160px.

This may be an extreme case, but it illustrates the problem. By grouping related properties (box model/layout, font properties, visual styles, etc.), it’s more obvious to authors what properties are affecting one another. The above example could be written like so:

.element {
  box-sizing: content-box;
  display: block;
  padding: 30px;
  width: 100px;

  font-family: "Open Sans", sans-serif;
  font-size: 13px;
  font-style: italic;
  font-weight: 400;

  color: blue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment