Skip to content

Instantly share code, notes, and snippets.

@AlexMelw
Last active February 22, 2021 09:50
Show Gist options
  • Save AlexMelw/fbd1401b60536f36cf5e8541e8fb3911 to your computer and use it in GitHub Desktop.
Save AlexMelw/fbd1401b60536f36cf5e8541e8fb3911 to your computer and use it in GitHub Desktop.
Hello wrold soper description

SCSS / SASS Basics

Nestings

image

Declaring variables

$variable-name: some-value

Extending

.some-class {
    @extend .class-name
}

Mixins

@mixin some-name($param-name) {
    ...
    @content;
    ...
}

@mixin some-name($param-name: some-default-value) {
    ...
    @content;
    ...
}

Usage:

@include some-name(50px);

List functions

length($list-name);

// if you select a negative nuber
// you start from the end of the array
// ex. nth($list-name, -1); // is the last element
nth($list-name, $one-base-index);

index($list-name, $value-to-search);

Color functions

    color: saturate($color: #9923FF, $amount: 50%);
    color: lighten($color: #9923FF, $amount: 10%);
    color: darken($color: #9923FF, $amount: 20%);
    color: adjust-hue($color: #9923FF, $degrees: 70deg);

@at-root

@media print {
    @at-root (with: media) {
        .bar {
            color: red;
        }
    }
}
// will produce
@media print {
  .bar {
    color: red;
  }
}
@media print {
    @at-root (without: media) {
        .bar {
            color: red;
        }
    }
}
// will produce
  .bar {
    color: red;
  }
@if a==b
    // ...
@else if a==c
    // ...
@elseif a==d
    // ...
@else
    // ...

Ternary operator

if(a == b, "they are equal", "they are NOT equal");

not (!) operator

@if not $bool {
    // We get in there
}

boolean functions (unitless and *-exists functions)

$value1: 42em;
$value2: 42;
$unitless: unitless($value1); // false
$unitless: unitless($value2); // true

$unicorn: 'rainbow';
$variable-exists: variable-exists('unicorn'); // true

Nested media queries

@media (min-width: 42em) {
    .foo {
      color: red;
  
      @media (max-width: 50em) {
        color: blue;
      }
    }
  }
// will produce
@media (min-width: 42em) {
  .foo {
    color: red;
  }
}
@media (min-width: 42em) and (max-width: 50em) {
  .foo {
    color: blue;
  }
}

@extend (!optional flag)

Use

@extend .bar !optional

if the parent class (.bar) might not be defined.

Functions' keywords arguments (named arguments)

// I know who to do it (like in C#)

Functions: unknown number of arguments

@function my-function($specific-argument, $extra-arguments...) { ... }

type-of()

You can check an object's type by doing type-of($object-dentifier).

@at-root

image

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