首页 > 解决方案 > 如何在 SASS 中使用 .startsWith

问题描述

我有一个像这样的 SASS 条件,它按我的预期工作,但你可以看到它太长了,我想重构它。如何使用 JavaScript 的 startsWith() 或 includes() 原型?

@if $styleName == margin or $styleName == margin-top or $styleName == margin-right or $styleName == margin-bottom or $styleName == margin-left {
//..something happens there
}

我正在寻找类似的解决方案:

@if $styleName.startsWith('margin'){
//..something happens there
}

标签: csssassnode-sass

解决方案


@if str-index($styleName, "margin") {}

推荐阅读