LoginSignup
0
1

More than 5 years have passed since last update.

scss positionのmixin

Last updated at Posted at 2014-01-10
@mixin position ($value:0 0,$coord:top left,$pos:absolute) {
    position: $pos;
    $length: length($value);
    @if $length == 1 {
        #{nth($coord,1)}: $value;
    }
    @else if $length == 2 {
        #{nth($coord,1)}: nth($value,1);
        #{nth($coord,2)}: nth($value,2);
    }
}

/*指定なし*/
.a { 
    @include position;
}

.a {
    position: absolute;
    top: 0;
    left: 0;
}

/*位置の値を1つ指定*/
.b { @include position(10px); }

.b {
    position: absolute;
    top: 10px;
}

/*指定の位置1箇所を指定*/
.c { @include position(10px, right); }

.c {
    position: absolute;
    right: 10px;
}

/*位置の値を2つ指定*/
.d { @include position(10px 5px); }

.d {
    position: absolute;
    top: 10px;
    left: 5px;
}

/*指定の位置2箇所を指定*/
.e { @include position(10px 5px, bottom right); }

.e {
    position: absolute;
    bottom: 10px;
    right: 5px;
}
0
1
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
0
1