5-6 @warn
本节编程练习不计算学习进度,请电脑登录imooc.com操作

@warn

@warn 和 @debug 功能类似,用来帮助我们更好的调试 Sass。如:

@mixin adjust-location($x, $y) {
  @if unitless($x) {
    @warn "Assuming #{$x} to be in pixels";
    $x: 1px * $x;
  }
  @if unitless($y) {
    @warn "Assuming #{$y} to be in pixels";
    $y: 1px * $y;
  }
  position: relative; left: $x; top: $y;
}

具体代码例子,请查看右侧代码编辑器中的代码。

任务

小伙伴们,现在让我们来练习一下@warn的用法吧!

  1. @mixin adjust-location($x, $y) {
  2. @if unitless($x) {//unitless是内置函数,判断数值是否有“单位”
  3. @warn "Assuming #{$x} to be in pixels";
  4. $x: 1px * $x;
  5. }
  6. @if unitless($y) {
  7. @warn "Assuming #{$y} to be in pixels";
  8. $y: 1px * $y;
  9. }
  10. position: relative; left: $x; top: $y;
  11. }
  12.  
  13.  
  14.  
  15. .botton{
  16. @include adjust-location(20px, 30);
  17. }
下一节