sass - 这个使用 mixin 函数的 SASS 代码是否过于冗长?
问题描述
我觉得这个mixin的代码太冗长了,请帮忙。
请随时通过有关 mixins 的任何建议。
@mixin bold { font-weight: bold; }
@mixin normal { font-weight: normal; }
@mixin font($bold, $normal) {
@if ($bold) {
@include bold
} @else {
font-weight: normal;
}
}
h1 { @include font(false, false) }
h2 { @include font(true, true) }
解决方案
你可以简化它:
$bold: 700;
$normal: 400;
h1 {
font-weight: $bold;
}
h2 {
font-weight: $normal;
}
推荐阅读
- jquery - 将数组从jquery传递给python函数时如何设置url?
- paypal-sandbox - 使用 PayPal 按钮连接
- performance - 有没有一种简单的方法可以在 Flutter 中尽可能多地添加 Const?
- asp.net-core - ASP.NET Core 中的单例允许多个实例
- python - Python - Pyproj 转换为 CSV 中的空白单元格返回 inf。如何忽略空白单元格?
- python - Python 日期时间:格式化字符串 %-m (%#m) 意外行为
- javascript - VanillaJS - 更改事件触发两次
- database - powerapps 表格中的字符太多?无法提交表单
- flutter - Truncate text to a specific digit Flutter Text widget
- javascript - 如何在反应js中有条件地传递数据?