-
Notifications
You must be signed in to change notification settings - Fork 2
/
4-use-if-and-else-to-add-logic-to-your-styles.html
61 lines (53 loc) · 1.68 KB
/
4-use-if-and-else-to-add-logic-to-your-styles.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!-- Use @if and @else to Add Logic To Your Styles
The @if directive in Sass is useful to test for a specific case - it works just like the if statement in JavaScript.
@mixin make-bold($bool) {
@if $bool == true {
font-weight: bold;
}
}
And just like in JavaScript, @else if and @else test for more conditions:
@mixin text-effect($val) {
@if $val == danger {
color: red;
}
@else if $val == alert {
color: yellow;
}
@else if $val == success {
color: green;
}
@else {
color: black;
}
}
Create a mixin called border-stroke that takes a parameter $val. The mixin should check for the following conditions using @if, @else if, and @else:
light - 1px solid black
medium - 3px solid black
heavy - 6px solid black
If $val is not light, medium, or heavy, the border should be set to none.
- Your code should declare a mixin named border-stroke which has a parameter named $val.
- Your mixin should have an @if statement to check if $val is light, and to set the border to 1px solid black.
- Your mixin should have an @else if statement to check if $val is medium, and to set the border to 3px solid black.
- Your mixin should have an @else if statement to check if $val is heavy, and to set the border to 6px solid black.
- Your mixin should have an @else statement to set the border to none.
-->
<style type='text/scss'>
@mixin border-stroke($val) {
@if $val == light {
border: 1px solid black;
} @else if $val == medium {
border: 3px solid black;
} @else if $val == heavy {
border: 6px solid black;
} @else {
border: none;
}
}
#box {
width: 150px;
height: 150px;
background-color: red;
@include border-stroke(medium);
}
</style>
<div id="box"></div>