css - 有没有办法在 sass 的地图中存储 mixins
问题描述
我想根据条件包含不同媒体查询的类。
我现在在做什么:
@mixin available($exclude-exp: each)
{
@if($exclude-exp == each) {
//include for each breakpoint
}
@else if($exclude-exp == global-only) {
.available {
flex: 1
}
}
@else if($exclude-exp == medium-only) {
@media screen and (min-width: $medium) {
.onmedium-available {
flex: 1
}
}
}
.
.
.
}
如果available
mixin$exclude-exps
作为地图接收并循环遍历地图,然后在该地图中包含所有 mixin,那对我来说会更好。
@mixin available($exclude-exps) {
@each $exclude-exp in $exclude-exps {
@include $exclude-exp();
}
}
$exclude-exps:(
each: @mixin() {
//a mixin to include for each breakpoint
},
global-only: @mixin() {
.available {
flex: 1
}
},
medium-only: @mixin() {
@media screen and (min-width: $medium) {
.onmedium-available {
flex: 1
}
}
},
.
.
.
)
然后我可以添加任意数量的字母$exclude-exps
。
解决方案
推荐阅读
- couchdb - 我可以使用值而不是键来查询视图吗?
- c# - 从百分比中删除小数点并在.net中保留百分比符号
- java - 将 targetSdkVersion 提高到 28 时,在路径上找不到类“com.google.android.gms.common.R$string”:DexPathList
- android - 为什么 Facebook 的 Unity SDK 没有将事件记录到分析?
- swift - 我打开了第二个视图,其中显示了集合中的一系列图像,我可以按下集合的图像以在第一个视图中使用图像吗?
- javascript - 如果付款成功或不成功,如何在重定向页面的顶部显示横幅
- c# - 团队中的 Bot 框架技能错误 - 有效域正确
- laravel - CSRF 令牌在 Laravel ajax 调用中不起作用
- docker - Docker System.Net.Http.HttpRequestException 上的 .netcore 微服务:无法分配请求的地址
- sql - 'C' 附近的语法不正确