获取通过与 SASS 混合定义的选择器属性值 [英] Get a selector property value defined through a mixin with SASS

查看:43
本文介绍了获取通过与 SASS 混合定义的选择器属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取通过mixin 为另一个选择器中的选择器定义的属性的值.例如:

Is it possible to get the value of a property defined through a mixin for a selector within another selector. For example:

@mixin mymixin($mywidth) {
  width: $mywidth;
}

div {
  @include mymixin(90%);
}

p {
  width: (20 / (([GET_SOMEWAY_DIV_WIDTH] * 960) / 100)) * 100;
}

推荐答案

使用变量:

$mywidth: 90%;

div {
    width: $mywidth;
}

p {
    width: (20 / (($mywidth * 960) / 100)) * 100;
}

<小时>

编辑:OP 编辑​​.AFAICS,当使用 mixin 参数时,这些值只能在 mixin 的范围内访问,当包含 mixin 时.重构以便将变量传递给包含的 mixin:


Edit re: OP edit. AFAICS, when using mixin arguments, those values are only accessible within the scope of the mixin, when the mixin is included. Refactor so that you pass a variable to the included mixin:

$mywidth: 90%;

@mixin mymixin($mywidth) {
  width: $mywidth;
}

div {
  @include mymixin($mywidth);
}

p {
  width: (20 / (($mywidth * 960) / 100)) * 100;
}

这篇关于获取通过与 SASS 混合定义的选择器属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆