view default/assets/scss/vendors/bourbon/library/_position.scss @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
line wrap: on
line source

@charset "UTF-8";

/// Provides a quick method for setting an element’s position. Use a `null`
/// value to “skip” a side.
///
/// @argument {string} $position [relative]
///   A CSS position value.
///
/// @argument {arglist} $coordinates [null]
///   List of lengths, defined as CSS shorthand.
///
/// @example scss
///   .element {
///     @include position(absolute, 0 null null 10em);
///   }
///
///   // CSS Output
///   .element {
///     left: 10em;
///     position: absolute;
///     top: 0;
///   }
///
/// @require {function} _is-length
///
/// @require {function} _unpack

@mixin position(
    $position: relative,
    $coordinates: null
  ) {

  @if type-of($position) == list {
    $coordinates: $position;
    $position: relative;
  }

  $coordinates: _unpack($coordinates);

  $offsets: (
    top:    nth($coordinates, 1),
    right:  nth($coordinates, 2),
    bottom: nth($coordinates, 3),
    left:   nth($coordinates, 4),
  );

  position: $position;

  @each $offset, $value in $offsets {
    @if _is-length($value) {
      #{$offset}: $value;
    }
  }
}