Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sass CSS边距循环每次递增X个数量_Sass - Fatal编程技术网

Sass CSS边距循环每次递增X个数量

Sass CSS边距循环每次递增X个数量,sass,Sass,我想知道是否可以用SCS来实现这一点?每次递增X 这很棘手,因为需要更新-s或-md而不是数字 @for $i from 1 through 6 { .u-marg-t-#{$i} { margin-top: 0px + ($i * 8); } } 除此之外,这里的@for是不是最好的方法 纯CSS输出 .u-marg-t { &-xs { margin-top: 8px; } &-

我想知道是否可以用SCS来实现这一点?每次递增X

这很棘手,因为需要更新
-s
-md
而不是数字

  @for $i from 1 through 6 {
      .u-marg-t-#{$i} {
        margin-top: 0px + ($i * 8);
      }
    } 
除此之外,这里的
@for
是不是最好的方法

纯CSS输出

.u-marg-t {
    &-xs {
        margin-top: 8px;
    }

    &-sm {
        margin-top: 16px;
    }

    &-md {
        margin-top: 24px;
    }

    &-lg {
        margin-top: 32px;
    }

    &-xl {
        margin-top: 43px;
    }

    &-xxl {
        margin-top: 50px;
    }
}

.u-marg-b {
    &-xs {
        margin-bottom: 8px;
    }

    &-sm {
        margin-bottom: 16px;
    }

    &-md {
        margin-bottom: 24px;
    }

    &-lg {
        margin-bottom: 32px;
    }

    &-xl {
        margin-bottom: 43px;
    }

    &-xxl {
        margin-bottom: 50px;
    }
}

您可以使用带有要使用的后缀的列表,并在for循环中进行迭代。下面是一个例子:

$sizes: xs, sm, md, lg, xl, xxl;

@for $i from 1 through 6 {
    .u-marg-t-{
        &#{nth($sizes, $i)} {
            margin-top: 0px + ($i * 8);
        }
    }
}
$sizes是带有后缀的列表。在循环中,我使用函数n($list,$I)获取列表中$I位置的项。

您想要的是“纯CSS输出”吗?