Organizing partials for your stylesheets can help to: Quickly add and remove elements/features, reduce merge conflicts, reduce ramp-up time, and keep your styles out of the html markup.
Key Structure Points
Have one master file to visualize your cascades.
Separate Visual and Positional Styles.
Separation of .class
Visual styles belong in mixins. Example: If you’re styling a button, that button’s mixin should be defined in a _buttons.scss partial. This would include the gradient, shadow, :hover, :focus and :active states.
Positional styles are best suited for page-specific files. Using our button, styles for position, margin, height and width would be defined on a per-page basis.
Padding, height and width can be tricky at times. Our button style may have some standard padding, but you may feel the need to customize on a page. This is best done in _yourpage.scss rather than in the general style rules.
Pull it together by chaining @mixins or @extend to apply styles. SASS. By using @mixins, your presentational markup will stay within the stylesheet and away from your html. The beauty of that is 1-control point over visual style, 1-control point for the positional style, and best of all: 1-control point for the semantic class of your element.
Reset the browser defaults to take control. This will greatly improve the consistency of your styles across devices. The entent of your rest file is up to you and your design goals. A very important piece of the reset file is the box-sizing: border-box.
_reset.scss
12345
*{@include box-sizing(border-box);//save your sanitymargin:0;padding:0;}
// sample brand color palette.$off-white:#FEFEFE;$blackblue:#162934;$lightblue:#29AAE2;$darkblue:#006FAB;$lightpink:#C9006B;$maroon:#7C0040;
Typography
@font-face, and typeface @mixins. I like to define @mixins for an icon font and a few weights of sans-serif and serif. This will create one control point for your typefaces, regardless of icon-fonts or design thrashes.
// import a sans and serif from google apis@importurl('http://fonts.googleapis.com/css?family=Crimson+Text:400italic,');@importurl(http://fonts.googleapis.com/css?family=PT+Sans:400,700);// declare your mixins for typeface-styles$serif-fallback:Georgia,"Times New Roman",serif;$sans-fallback:Helvetica,Arial,Sans-Serif;$serif:"Crimson Text",$serif-fallback;$sans:"PT Sans",$sans-fallback;@mixin light-text{color:$off-white;text-shadow:0-1pxrgba($blackblue,.3);}@mixin dark-text{color:$blackblue;text-shadow:01pxrgba($off-white,.3);}$body-copy-font-size:14px;$body-copy-line-height:20px;$h1-font-size:36px;$h1-line-height:44px;$h2-font-size:24px;$h2-line-height:30px;html,body{font-family:$sans;color:$body-copy-color;}h1{font-size:$h1-font-size;line-height:$h1-line-height;}h2{font-size:$h2-font-size;line-height:$h2-line-height;}
Z-index
Every z-index in the entire app. Probably one of the most important files to keep seperate. This will prevent you from dealing with 99, 99999, 99999999, etc. With a simple z-index file, you can use $variables to define z-indexes for various places and will always have a place to find all your z-index. This makes it very easy to solve z-index issues and transition to anther teammate.
_zindex.scss
1234
// ALL z-indices go here.$checkbox-mask-z:1;$overlay-z:2;$modal-z:3;
Base Elements
Base elements
Keep the visual-styles of your basic elements here. Things like background-colors and borders for the body, section, article, a, ul, li. Depending on the number of layouts in your app, this may even be a good spot to define the padding for the body or body > section.
You may notice that pieces of base_elements.scss need to be seperated after some time. Some form elements, like select and checkboxes may need their own stylesheets in order to keep forms.scss from becoming too large.
UI elements and partials
Tabs, tags, modals, header, footer, etc.
We’ve finally reached the place to begin adding some positional css, but not too much. We should only be assigning positional styling to our container’s/partial’s children. By staying inside of our partial’s own bounds we enable our containers/partials to be postioned by their super-view without conflict.
Start positioning those elements within your page. Watch out for the gotchas and take note if you start to use more than @mixins for visual styles. This could be sign that you’re either not sticking the styleguide you built, or maybe you could benefit from another @mixin in your deck.