css - 在 sass mixin 中添加断点
问题描述
我的最终目标是为移动设备(16px)和桌面(18px)设置一个字体大小,但是我使用这个 mixin 来控制字体大小。我如何调整 mixin 来实现这一点。为了让我有两个版本的 mixin:
@mixin font-size($size) {
font-size: $size;
font-size: calculateRem($size);
}
@function calculateRem($size) {
$remSize: $size / $font-size-root;
@return $remSize * 1rem;
}
解决方案
您可以在 mixin 中添加媒体查询:
@mixin font-size($desktopSize, $mobileSize) {
font-size: $desktopSize;
font-size: calculateRem($desktopSize);
// This is just and example mobile width
@media only screen and (max-width:639px){
font-size: $mobileSize;
font-size: calculateRem($mobileSize);
}
}
@function calculateRem($size) {
$remSize: $size / $font-size-root;
@return $remSize * 1rem;
}
$mobileSize
您可以通过将 设置为等于来进一步更新 mixin 参数$desktopSize
:
@mixin font-size($desktopSize, $mobileSize:$desktopSize)
这将防止遍历代码中使用单个参数的 mixin 的所有位置。
推荐阅读
- php - 如何使用 Laravel 中的路由将循环下拉值从视图传递到控制器?
- php - 转换为十进制时缺少前导零
- python - 不使用 SerializerMethodField 显示添加的字段
- spotfire - 是否可以在spotfire中从长字符串中提取固定格式的字符串?
- android - 如何更改 SwitchPreference 上的文本摘要颜色
- c# - 接收数据时,[serialport_datareceived]事件发生多次(使用虚拟串口)
- r - 从文件夹导入时缺少数据
- c++ - 在 C++ 中使用带有枚举的 Switch
- java - 使用 AspectJ 根据类型隔离具有相同名称的方法?
- http - 单击链接或输入 URL 时 GET 与 POST?