File: _nested-context.scss

package info (click to toggle)
compass-toolkit-plugin 2.10.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 63; javascript: 49; makefile: 2; sh: 1
file content (31 lines) | stat: -rw-r--r-- 985 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// simple function to find the context of a nested percentage.
@function nested-context($contexts: null) {
  $contexts: if($contexts != null, $contexts, toolkit-get('nested context contexts'));

  // First level deep is always 100%
  $percentage: 100%;

  // Loop through each level
  @each $context in $contexts {
    // Invert the percentage to find context
    $percentage: percentage($percentage / $context);
  }
  // Return final percentage
  @return $percentage;
}

// mixin to make things easier
@mixin nested-context($contexts: null, $position: null) {
  $contexts: if($contexts != null, $contexts, toolkit-get('nested context contexts'));
  $position: if($position != null, $position, toolkit-get('nested context position'));

  width: nested-context($contexts);
  @if $position == "center" {
    position: relative;
    left: 50%;
    margin-left: nested-context($contexts) * -.5;
  }
  @if $position == "right" {
    margin-left: nested-context($contexts) * -1 + 100%;
  }
}