Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bizhe
Created December 29, 2019 07:06
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 bizhe/70791e23d59602fd6448870808f70db1 to your computer and use it in GitHub Desktop.
Save bizhe/70791e23d59602fd6448870808f70db1 to your computer and use it in GitHub Desktop.
sass cheatsheet
Comments
/* Block comments */
// Line comments
// Variables
$red: #833;
body {
color: $red;
}
// Nesting
.markdown-body {
p {
color: blue;
}
&:hover {
color: red;
}
}
// Mixins
@mixin heading-font {
font-family: sans-serif;
font-weight: bold;
}
h1 {
@include heading-font;
}
with parameters
@mixin font-size($n) {
font-size: $n * 1.2em;
}
body {
@include font-size(2);
}
with default values
@mixin pad($n: 10px) {
padding: $n;
}
body {
@include pad(15px);
}
with a default variable
// Set a default value
$default-padding: 10px;
@mixin pad($n: $default-padding) {
padding: $n;
}
body {
@include pad(15px);
}
// Composing
@import './other_sass_file`;
// For loops
@for $i from 1 through 4 {
.item-#{$i} { left: 20px * $i; }
}
// Conditionals
@if $position == 'left' {
position: absolute;
left: 0;
}
@else {
position: static;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment