关于SCSS,媒体查询代码优化错误?
想写一段关于媒体查询的代码,如下:
$grid-map: (
gridlg: 2000px,
gridmd: 1500px,
gridsm: 1000px,
grid6p: 500px
);
@mixin grid($width){
@if($width<map-get($grid-map, grid6p)){
@media only screen and (max-width: map-get($grid-map, grid6p)){
@content;
}
}@else if($width<map-get($grid-map, gridsm)){
@media only screen and (max-width: map-get($grid-map, gridsm)){
@content;
}
}@else if($width<map-get($grid-map, gridmd)){
@media only screen and (max-width: map-get($grid-map, gridmd)){
@content;
}
}@else if($width<map-get($grid-map, gridlg)){
@media only screen and (max-width: map-get($grid-map, gridlg)){
@content;
}
}
}
以上代码目前达到了预期的效果,但想对代码进行如下优化,如下:
$grid-map: (
gridlg: 2000px,
gridmd: 1500px,
gridsm: 1000px,
grid6p: 500px
);
@mixin grid($width){
@each $key, $value in $grid-map{
@if($width<$value){
@media only screen and (max-width: map-get($grid-map, $key)){
@content;
}
}
}
}
但是编译有问题,似乎我对 map 属性理解的不透彻,还望高手指导解答,谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论