[Sass] Level 6: MATH + COLOR -- Ex

ARITHMETIC I

To ensure consistent spacing between columns, our stylesheet has a reusable $gutter variable. Subtract the width values in .factory and .highrise by $gutter to account for the margin.

复制代码
$gutter: 20px;

.factory {
  background: #fff;
  margin-right: $gutter;
  width: 600px;
}
.highrise {
  background: #797979;
  margin-right: $gutter;
  width: 300px;
}
复制代码

Answer:

复制代码
$gutter: 20px;

.factory {
  background: #fff;
  margin-right: $gutter;
  width: 600px-$gutter;
}
.highrise {
  background: #797979;
  margin-right: $gutter;
  width: 300px-$gutter;
}
复制代码

 

ARITHMETIC II

Your coworker has been attempting to set the font size of span elements inside .sign to half the.sign font size, without success. Knowing what you do about triggering division, utilize parentheses to fix the problem.

.sign {
  font-size: 3.75em;
  font-weight: bold;
  padding: 20px 40px;
  span {
    font-size: 3.75em / 2;
  }
}

Answer:

.sign {
  font-size: 3.75em;
  font-weight: bold;
  padding: 20px 40px;
  span {
    font-size: (3.75em /2);
  }
}

 

ARITHMETIC III

3.75em has been recurring throughout our stylesheet, so let's move it to a variable and use that variable where possible. Remember: utilizing a variable also triggers division, which removes the need for our parentheses.

.sign {
  font-size: 3.75em;
  font-weight: bold;
  padding: 20px 40px;
  span {
    font-size: (3.75em / 2);
  }
}

Answer:

复制代码
$base-size: 3.75em;

.sign {
  font-size: $base-size;
  font-weight: bold;
  padding: 20px 40px;
  span {
    font-size: $base-size / 2;
  }
}
复制代码

 

CONCATENATION

Our @if directive performs a bit of string concatenation, but we'd prefer if the output value had quotes around it. Tweak the directive to ensure this is the case.

复制代码
$theme: modern;
$font: 'serif';

@if $theme == modern {
  $font: sans- + $font;
}

.sign {
  font-family: $font;
}
复制代码

Answer:

复制代码
$theme: modern;
$font: 'serif';

@if $theme == modern {
  $font: "sans-" + $font;
}

.sign {
  font-family: $font;
}
复制代码

 

NUMBER FUNCTIONS I

On reflection, it'd be nice to have a cleaner font size to work with after performing arithmetic inside our span. Use the appropriate built-in function to round the span's font size to the nearest whole number.

复制代码
$size: 3.75em;

.sign {
  font-size: 3.75em;
  font-weight: bold;
  padding: 20px 40px;
  span {
    font-size: $size / 2;
  }
}
复制代码

Answer:

复制代码
$size: 3.75em;

.sign {
  font-size: 3.75em;
  font-weight: bold;
  padding: 20px 40px;
  span {
    font-size: round($size / 2);
  }
}
复制代码

 

NUMBER FUNCTIONS II

Our .factory and .highrise declarations are lacking responsiveness: using the target / context formula, the given $context variable, and percentage(), give each declaration a fluid width. No need to refactor this into a separate function, just add your percentage() calls within.factory and .highrise.

复制代码
$context: 960px;

.factory {
  background: #fff;
  width: 600px;
}
.highrise {
  background: #797979;
  width: 300px;
}
复制代码

Answer:

复制代码
$context: 960px;

.factory {
  background: #fff;
  width: percentage(600px / $context);
}
.highrise {
  background: #797979;
  width: percentage(300px / $context);
}
复制代码

 

COLOR SHORTHAND

We've stored a hex color value in $color-base, but the rgb equivalent (121,121,121) is being used in .modal. Use the shorthand version of rgba() to make use of the already-available$color-base value.

$color-base: #797979;

.modal {
  background: rgba(121,121,121,0.75);
  border: 1px solid $color-base;
  padding: 20px;
}

Answer:

$color-base: #797979;

.modal {
  background: rgba($color-base,0.75);
  border: 1px solid $color-base;
  padding: 20px;
}

 

COLOR FUNCTIONS I

Anchor elements are currently missing a hover state - add one via nesting which sets a color15% lighter than $color-link.

$color-link: #3097b4;

a {
  color: $color-link;
  text-decoration: underline;
}

Answer:

复制代码
$color-link: #3097b4;

a {
  color: $color-link;
  text-decoration: underline;
  &:hover{
        color: lighten($color-link, 15%);
    }
}
复制代码

 

 

COLOR FUNCTIONS II

Our newly-added hover state isn't bad, but we'd like to up the intensity a bit. Keeping the lighter value, increase the saturation by 20%. Note: look to the :active state to see an example of nested color functions.

复制代码
$color-link: #3097b4;

a {
  color: $color-link;
  text-decoration: underline;
  &:hover {
    color: lighten($color-link, 15%);
  }
  &:active {
    color: desaturate(darken($color-link, 15%), 25%);
  }
}
复制代码

Answer:

复制代码
$color-link: #3097b4;

a {
  color: $color-link;
  text-decoration: underline;
  &:hover {
    color: saturate(lighten($color-link, 15%), 20%);
  }
  &:active {
    color: desaturate(darken($color-link, 15%), 25%);
  }
}
复制代码

 

COLOR FUNCTIONS III

Unfortunately, our hover state just isn't obvious enough. Remove the saturate() and lighten()additions, and use a color function to invert the value.

复制代码
$color-link: #3097b4;

a {
  color: $color-link;
  text-decoration: underline;
  &:hover {
    color: saturate(lighten($color-link, 15%), 20%);
  }
  &:active {
    color: desaturate(darken($color-link, 15%), 25%);
  }
}
复制代码

Answer:

复制代码
$color-link: #3097b4;

a {
  color: $color-link;
  text-decoration: underline;
  &:hover {
    color: invert($color-link);
  }
  &:active {
    color: desaturate(darken($color-link, 15%), 25%);
  }
}
复制代码

 

Read More: http://sass-lang.com/documentation/Sass/Script/Functions.html

posted @   Zhentiw  阅读(323)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示