如何在ionic4的类中调用变量?

时间:2019-06-25 16:48:19

标签: css sass ionic4

是否可以调用在类内部的variables.scss中创建的变量?

我尝试了下面的代码,但不起作用

这是我的variables.scss:

$test : (
  color: purple,
  font-style: normal,
  font-weight: normal,
  font-size: 13px
  );

这是我的html(ionic4)


<ion-label class="test">Just testing!</ion-label>
<h1 class="test">Testing again</h1>

我该如何解决?

2 个答案:

答案 0 :(得分:0)

您不能从一个类中调用具有多个样式属性的变量,但是可以扩展另一个类。

.test {
  color: purple;
  font-style: normal;
  font-weight: normal;
  font-size: 13px;
}

.another {
  @extend .test;
}

Working Prototype

此处有更多信息:https://coderwall.com/p/7p7w2a/when-to-use-sass-mixins-extends-and-variables

答案 1 :(得分:-1)

经过大量研究,我得出的结论是,解决问题的最佳方法是创建一个混合

像这样:

@mixin test{
  color: purple;
  font-style: normal;
  font-weight: normal;
  font-size: 13px;
  }

.test{
  @include test();
}