Seattle WordPress Dev Meetup
July 2015
Darren Krape | @dkrape
Preprocessor for CSS
@import "base/reset";
//Helpers
@import "helpers/mixins";
@import "helpers/variables";
//Layout
@import "layout/grid";
//Components
@import "components/alerts";
@import "components/buttons";
//Sections
@import "sections/home"
@import "sections/contact"
$margin-base: 1rem;
$color-primary: blue;
.navigation {
background: $color-primary;
margin-bottom: $margin-base;
}
.navigation {
background: blue;
margin-bottom: 1rem;
}
SCSS
CSS
.article {
background: white;
border: 1px solid #ccc;
h1 {
font-size: 1.5rem;
font-weight: bold;
}
}
.article {
background: white;
border: 1px solid #ccc;
}
.article h1 {
font-size: 1.5rem;
font-weight: bold;
}
SCSS
CSS
$gutter: 10px;
.article {
margin-bottom: $gutter * 2;
}
.article {
margin-bottom: 20px;
}
SCSS
CSS
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
.box { @include border-radius(10px); }
.box {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
border-radius: 10px;
}
SCSS
CSS
$ gem update --system
$ gem install sass
$ gem install compass
1. Terminal: Install Sass
If you get an error, add “sudo” before each command
CSS authoring framework
/config.rb
/style.css
/img/
/js/
/scss/
/scss/style.scss
2. Install your theme
3. Create folders and files in your theme
$margin: 16px
.content-navigation
margin-bottom: $margin
$margin: 16px;
.content-navigation {
margin-bottom: $margin;
}
.sass "indented syntax"
.scss "block format"
http_path = "/" #root level target path
css_dir = "." #directory of default style.css file (root level of our theme)
sass_dir = "sass" #sass directory
images_dir = "img" #image directory
javascripts_dir = "js" #JavaScript directory
output_style = :expanded
4. Configure config.rb
.main {
color: #fff;
background-color: #000; }
.main p {
width: 10em; }
.main {
color: #fff;
background-color: #000;
}
.main p {
width: 10em;
}
Nested (default)
Expanded
.main { color: #fff; background-color: #000; }
.main p { width: 10em; }
.main{color:#fff;background-color:#000}.main p{width:10em}
Compact
Compressed
$ cd yoursite/wp-content/themes/yourtheme
$ compass watch
5. In terminal, "Watch" your project
6. Write some Sass, edit "sass/style.scss"
$background-color: red;
body {
background: $background-color;
}
7. Save the file and see it compile
$32
Jetpack: "Appearance"
> "Edit CSS"
PCs: ...umm...
@import "css/components/buttons"
CSS (not awesome)
Sass (awesome)
@import url('css/components/buttons.css');
//Base
@import "compass/reset"
//Helpers
@import "helpers/mixins";
@import "helpers/variables";
//Typography
@import "base/typography";
//Layout
@import "layout/grid";
@import "layout/header";
@import "layout/footer";
//Components
@import "components/buttons";
@import "components/navigation";
@import "components/tables";
@import "components/widgets";
//Sections (pages)
@import "sections/home";
@import "sections/contact";
// Third-party
@import "vendor/jquery.ui.core";
//Refile
@import "junk";
In "scss/style.scss"
// Typography
$font__family--main: "Arial", sans-serif;
$font__family--secondary: "Roboto", serif;
$font__size--sm: 1rem;
$font__size--md: 1.5rem;
$font__size--lg: 2rem;
$font__size--xlg: 3rem;
// Sizing
$spacing--base: 3rem;
$spacing--sm: ( $spacing--base * 0.5 );
$spacing--md: $spacing--base;
$spacing--lg: ( $spacing--base * 1.5 );
$spacing--xlg: ( $spacing--base * 2.25 );
// Color: Primary (Peach)
$color__primary: #fb9e82;
$color__primary--dark: darken( $color__primary, 10% );
$color__primary--light: lighten( $color__primary, 5% );
// Color: Trim (Warm gray)
$color__trim: #97a0ab;
$color__trim--dark: #545a5f;
$color__trim--light: #b9bedb;
// Breakpoints
$breakpoint--full: 1000px;
$breakpoint--md: 600px;
$breakpint--sm: 300px;
.widget {
border: 1px solid #ccc;
padding: 10px;
h1 {
font-size: 2rem;
margin-bottom: 6px;
}
section {
background: gray;
}
}
.widget {
border: 1px solid #ccc;
padding: 10px;
}
.widget h1 {
font-size: 2rem;
margin-bottom: 6px;
}
.widget section {
background: gray;
}
Sass
CSS
.home {
background: white;
.content {
font-size: 1rem;
.sidebar {
margin-left: 10px;
.widget {
border: 1px solid #ccc;
}
}
}
}
.home {
background: white;
}
.home .content {
font-size: 1rem;
}
.home .content .sidebar {
margin-left: 10px;
}
.home .content .sidebar .widget {
border: 1px solid #ccc;
}
Sass
CSS
a {
color: blue;
&:hover {
color: red;
}
&:visited {
color: purple;
}
&:after {
content: "...";
}
}
a {
color: blue;
}
a:hover {
color: red;
}
a:visited {
color: purple;
}
a:after {
content: "...";
}
Sass
CSS
.banner {
background: gray;
color: white;
&.success {
background: green;
}
}
.banner {
background: gray;
color: white;
}
.banner.success {
background: green;
}
Sass
CSS
.header {
padding: 10px;
.theme-light & {
background: white;
color: black;
}
.theme-dark & {
background: black;
color: white;
}
}
.header {
padding: 10px;
}
.theme-light .header {
background: white;
color: black;
}
.theme-dark .header {
background: black;
color: white;
}
Sass
CSS
$col--width: 60px;
$gutter--width: 14px;
.row { clear: both; margin-bottom: 10px; overflow: hidden; }
.col { background: red; float: right; margin-right: $gutter--width; }
.col1 { width: $col--width; }
.col2 { width: ( $col--width * 2 ) + ( $gutter--width * 1 ); }
.col3 { width: ( $col--width * 3 ) + ( $gutter--width * 2 ); }
Sass
.row {
clear: both;
margin-bottom: 10px;
overflow: hidden; }
.col {
background: red;
float: right;
margin-right: 14px; }
.col1 {
width: 60px; }
.col2 {
width: 134px; }
.col3 {
width: 208px; }
CSS
<div class="row">
<div class="col col1"> </div>
<div class="col col1"> </div>
<div class="col col1"> </div>
</div>
<div class="row">
<div class="col col1"> </div>
<div class="col col2"> </div>
</div>
<div class="row">
<div class="col col3"> </div>
</div>
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
.box {
@include border-radius(10px);
}
.box {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
border-radius: 10px;
}
Sass
CSS
@if
@for
@while
@each
$col--count: 4;
$col--width: 60px;
$gutter--width: 14px;
.col {
float: right;
margin-right: $gutter--width;
}
@for $i from 1 through $col--count {
.col-#{$i} {
width: ( $col--width * $i ) + ( $gutter--width * ( $i - 1 ) );
@extend .col;
}
}
Sass
.col, .col-1, .col-2, .col-3, .col-4 {
float: right;
margin-right: 14px; }
.col-1 {
width: 60px; }
.col-2 {
width: 134px; }
.col-3 {
width: 208px; }
.col-4 {
width: 282px; }
CSS
@mixin grid( $col--width, $col--count, $gutter--width ) {
.col {
float: right;
margin-right: $gutter--width;
}
@for $i from 1 through $col--count {
.col-#{$i} {
width: ( $col--width * $i ) + ( $gutter--width * ( $i - 1 ) );
@extend .col;
}
}
}
@include grid( 60px, 4, 14px );
Sass
.col, .col-1, .col-2, .col-3, .col-4 {
float: right;
margin-right: 14px; }
.col-1 {
width: 60px; }
.col-2 {
width: 134px; }
.col-3 {
width: 208px; }
.col-4 {
width: 282px; }
CSS
@mixin nav( $nav-items ) {
.nav-item {
float: left;
height: 30px;
}
@each $curr-nav in $nav-items {
.nav-#{$curr-nav} {
background-image: url('../i/nav-icon-#{$curr-nav}');
}
}
}
$nav-items: 'home', 'services', 'contact';
@include nav( $nav-items );
Sass
.nav-item {
float: left;
height: 30px; }
.nav-home {
background-image: url("../i/nav-icon-home"); }
.nav-services {
background-image: url("../i/nav-icon-services"); }
.nav-contact {
background-image: url("../i/nav-icon-contact"); }
CSS