CSS shorthand for positioning

前端 未结 5 1323
小鲜肉
小鲜肉 2020-12-05 17:17

There are any shorthand for top right bottom left or for width and height ?

I have a lo

5条回答
  •  情歌与酒
    2020-12-05 17:42

    If you want shorthand for this, you're gonna need to make what's called a mixin with Sass. Don't know what it is? Look it up!

    @mixin position($position, $args) {
      @each $o in top right bottom left {
            $i: index($args, $o);
    
        @if $i and $i + 1< = length($args) and type-of(nth($args, $i + 1)) == number  {
              #{$o}: nth($args, $i + 1);
        }
      }
    
      position: $position;
    }
    
    @mixin absolute($args) {
            @include position("absolute", $args);
    }
    
    @mixin fixed($args) {
            @include position("fixed", $args);
    }
    
    @mixin relative($args) {
            @include position("relative", $args);
    }
    

    Here's a link that explains it:

    http://hugogiraudel.com/2013/08/05/offsets-sass-mixin/

提交回复
热议问题