CSS预处理器(Sass、Less)专题测试
考察知识点
- Sass与Less基础语法对比
- 变量定义与使用($variable vs @variable)
- 嵌套规则与父选择器引用
- 混合宏(Mixin)的定义与调用
- 函数与运算
- 继承/扩展(@extend vs :extend)
- 模块导入与模块化组织
- 条件语句与循环
💡 参考答案在文末
判断题
1
Sass的占位选择器 %placeholder 与普通类选择器的区别是:占位选择器本身不会输出到CSS,只有被 @extend 扩展时才会出现在编译结果中。
2
在Sass嵌套规则中,& 符号总是代表当前所在块的父选择器。
3
在Sass中,在嵌套规则内定义的变量默认是局部变量,只在该规则块内有效。使用 !global 标记可以将变量定义为全局变量。
4
@forward 规则用于转发另一个模块的所有内容,使得导入当前模块的用户可以访问被转发模块的变量、mixin和函数。
单选题
5
以下Sass代码编译后的CSS是什么?
scss
.error {
color: red;
border: 1px solid red;
}
.serious-error {
@extend .error;
font-weight: bold;
}
6
关于Sass中 mixin 和 extend 的区别,以下说法正确的是?
7
以下关于Sass模块导入的说法,错误的是?
8
以下Sass代码编译后,.outer 和 .inner 的 color 值分别是?
scss
$color: red;
.outer {
$color: blue;
color: $color;
.inner {
$color: green !global;
color: $color;
}
color: $color;
}
.final {
color: $color;
}
9
以下Sass代码编译后的CSS是什么?
scss
.nav {
ul {
margin: 0;
padding: 0;
}
li {
display: inline-block;
}
a {
color: blue;
&:hover {
color: red;
}
}
}
10
以下Sass代码编译后,.box 的 width 值是多少?
scss
$base: 100px;
.box {
width: $base * 2 + 50px - $base / 2;
}
11
关于Sass和Less的语法差异,以下说法正确的是?
12
以下Sass代码编译后的CSS是什么?
scss
$theme: dark;
.box {
@if $theme == light {
background: white;
color: black;
} @else if $theme == dark {
background: black;
color: white;
} @else {
background: gray;
color: gray;
}
}
13
以下Sass代码编译后的CSS是什么?
scss
@mixin border-radius($radius) {
border-radius: $radius;
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
}
.box {
@include border-radius(10px);
}
14
以下Sass代码生成的CSS类数量是多少?
scss
$colors: (primary: blue, secondary: green, warning: yellow, danger: red);
@each $name, $color in $colors {
.btn-#{$name} {
background: $color;
&:hover {
@if $name == danger {
background: darken($color, 10%);
} @else {
background: lighten($color, 10%);
}
}
}
}
多选题
15
关于Sass的 @extend,以下说法正确的是?
16
以下Sass内置函数的用途描述正确的是?
17
关于Sass mixin,以下说法正确的是?
填空题
18
以下Sass代码使用循环生成多个类,填写编译后的CSS:
scss
@for $i from 1 through 3 {
.col-!!1_#{$i}!! {
width: !!2_100px * $i!!;
}
}
编译后第一个类 .col-1 的宽度是 ____________,第三个类 .col-3 的宽度是 300px。
19
Sass支持属性嵌套,以下代码编译后的CSS是:
scss
.box {
font: {
family: Arial;
size: 14px;
weight: bold;
}
}
编译结果:____________
参考答案
1.正确
2.正确
3.正确
4.正确
5.A
6.A
7.D
8.B
9.A
10.A
11.D
12.A
13.A
14.B
15.A;B;C;D
16.A;B;C;E
17.A;B;C;E
18.#{$i};100px * $i;100px
19..box { font-family: Arial; font-size: 14px; font-weight: bold; }
想在手机上练习这套试卷?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码