在断点处更改 SASS 变量

问题描述

是否可以在断点处更改 SASS 变量? 下面的代码只是例如我想要实现的

$flex-direction: row;

@include breakpoint(768){
  $flex-direction: column;
}

解决方法

不,您不能这样做,在您的示例中,这也没有任何意义。就这样写代码:

.your-classname {

    flex-direction: row;

    @include breakpoint(768) {
        flex-direction: column;
    }
}

对于永不改变的值/属性,无需使用 scss 变量。只要不完全重写 CSS 规范,值/关键字 column 就不会改变。如果您使用 px 等颜色或大小值,则使用 scss 变量是有意义的。

也许您想使用自定义属性 - 请在此处查看更多信息: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties