Welcome to the XO CSS Styleguide. It's pretty rad. Before reading this, it's recommended that you are familiar with or research specificity, the SCSS syntax, and common network bottlenecks/reasons for slow page loading time.
Some of these practices are not fully implemented yet so please update/upgrade files as you work on them.
If you're visiting from the internet, feel free to learn from our style. This is a guide we use for our own apps internally at XO. We encourage you to set up one that works for your own team.
:
in property declarations.{
in rule declarations.#000
unless using rgba.//
for inline comments (instead of / * * /
).Here is good example syntax:
// This is a good example!
.styleguide-format {
border: 1px solid #0f0;
color: #000;
background: rgba(0,0,0,0.5);
.border-radius(5px, 30px);
// Disables strange chrome-adding behavior in Safari.
-webkit-rendering-shadow-chrome: false;
}
@variable
or .mixin
that is used in more than one file should be defined in assets/css/globals/
. Others should be put at the top of the file where they're used.All styles should ALWAYS be written in well-orgainzed files. CSS should never be written inline in your HTML for any reason.
In general, the CSS file organization should be separated into page/content specific files and any shared code written as modules and follow something like this:
assets
└── css
├── globals
│ ├── fonts.scss
│ ├── icons.scss
│ ├── colors.scss
│ ├── header.scss
│ ├── footer.scss
│ └── agent.scss
│
├── partner
│ ├── bhg.scss
│ ├── allentate.scss
│ └── remax.scss
│
├── global.scss
├── homepage.scss
├── change_of_address.scss
└── agent_signup.scss
You should explicitly import any global SCSS that is required for the document you're working on. Do not import files that are not in the globals folder. If they are shared styles, they should always go in globals. Here's a good example:
@import 'globals/fonts';
@import 'globals/colors';
.rule {
.font-family();
background: green;
...
}
Any partner-specific CSS should be stored in the assets/css/partner/ folder. This is a temporary measure as we move to storing partner style options in a more scalable manner.
Use 62.5%
for the root font-size
, because it makes all other numbers easier to understand. For all other font-size
s, use em
s. This is because versions of IE below 10 do not offer zoom functionality and can only change relative font sizes for accessibility. For the same reason, don't use rem
s because of their poor historical browser support. Additionally, line-height
should never have a unit because it does not inherit a percentage value of its parent element, but instead is based on a multiplier of the font-size.
Reference: Pixels vs Ems
Never reference js-
prefixed class names from CSS files. js-
are used exclusively from JS files. Try to give classes descriptive names like .header-logo-container
instead of something like .blue
.
Because of their very high specificity it's recommended to never use IDs for CSS. Use a descriptive class name and nest as little as possible so that your modular CSS rules are easy to override in other sections of the site.
Only start with an element + class namespace when writing styles that need to override other classes and when the styles will only ever be applied to one type of element, prefer concise selectors by default, and use as little specificity as possible. Always include a newline between selectors. Here is a good example:
<ul class="category-list">
<li class="item">Category 1</li>
<li class="item">Category 2</li>
<li class="item">Category 3</li>
</ul>
// Needed to override .category-list in bootstrap.
ul.category-list {
padding-left: 20px;
.list-item { // direct descendant selector > for list items
list-style-type: disc;
a { // minimal specificity for all links
color: #ff0000;
}
}
}
#selector
) make sure that you have no more than one in your rule declaration. A rule like #header .search #quicksearch { ... }
is considered harmful..listings-layout.bigger
use rules like .listings-layout.listings-bigger
. Think about ack/grepping
your code in the future.disabled
, mousedown
, danger
, hover
, selected
, active
and any others used by Bootstrap should always be namespaced by a class (button.selected
is a good example).We use Bootstrap's grid system and this should be embraced in design and development as much as possible. The grid system keeps positioning styles out of our CSS and makes our HTML easier to read and write.