1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ SASS ] position指定用のmixin

Last updated at Posted at 2019-01-31

abs == absolute
fixed == fixed
それ以外はrelativeの扱いにします。
数値は top, right, bottom, left の順に。

##mixin

_mixin.scss

// position:
// ---------------------------------------- //
@mixin position($def: relative, $t: auto, $r: auto, $b: auto, $l: auto){
	@if $def == abs {
        position: absolute;
    } @else if $def == fixed {
        position: fixed;
    } @else {
        position: relative;
    }
	@if $t != auto and $t != n { top: $t; }
	@if $r != auto and $r != n { right: $r };
	@if $b != auto and $b != n { bottom: $b };
	@if $l != auto and $l != n { left: $l };
}

// @include position;
// -> position: relative;

// @include position(abs);
// -> position: absolute;

// @include position(fixed, 0, n, n, 0);
// -> position: fixed;
//    top: 0;
//    left: 0;

##SCSS

example.scss

.example {
	@include position(absolute, 20px, n, n, 55px);
}

##CSS

example.css

.example {
	position: absolute;
	top: 20px;
	left: 55px;
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?