Skip to content

Instantly share code, notes, and snippets.

@ryon
Created July 9, 2014 01:10
Show Gist options
  • Save ryon/8820be10292935567622 to your computer and use it in GitHub Desktop.
Save ryon/8820be10292935567622 to your computer and use it in GitHub Desktop.
css {
should-look: like-this;
/* one space after the selector */
/* opening brace on the same line */
/* 4-space indent */
/* closing brace on its own line */
/* one blank line between rules */
}
.one-liners { can-look: like-this; } /* but only do this if the rule has only one property and it's unlikely to gain more */
grouped,
selectors {
go: 'on separate lines'; /* single quotes around strings in CSS and JS, double quotes for HTML attributes */
}
colors {
use: #b4d455; /* lowercase alpha digits */
use: #cdc; /* three-digit hex if it's available */
use: white; /* keyword if it's common */
}
sort {
all: properties;
in: alphabetical;
order: for-sanity;
}
div {
/* always use the shortest notation possible for box-model lengths */
/* remember that bottom will copy top and left will copy right, unless otherwise indicated */
/* also, leave units off zero values */
border-radius: 2px; /* not 2px 2px 2px 2px */
border-width: 1px 0; /* not 1px 0px 1px 0px */
margin: 10px 20px 30px; /* not 10px 20px 30px 20px; */
padding: 10px 20px 30px 40px; /* write out all four only if necessary */
}
div {
/* sometimes it's more readable to declare an all-around value and then "tweak" it */
/* this makes the outlier stand out better */
padding: 10px;
padding-right: 0;
/* not padding: 10px 0 10px 10px */
/* but this is not a hard and fast rule */
}
@gawinowicz
Copy link

Another one:

  • Avoid using shorthand for things like background, where there are a bunch of values that you might be inadvertently overwriting by omission. Use the individual properties instead to avoid cascade weirdness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment