2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Use @if and @else to Add Logic To Your Styles
|
|
|
|
---
|
|
|
|
## Use @if and @else to Add Logic To Your Styles
|
|
|
|
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
## Solution
|
|
|
|
```sass
|
|
|
|
<style type='text/sass'>
|
|
|
|
@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>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
<div id="box"></div>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
Added SASS solutions, fixed typos, code formatting (#34792)
* Added SASS solution and output CSS
* Fixed typo, added code formatting
The example code outputs for "start to end" and "start through end" were swapped. "1 to 3" does not include the end number, so should output "1 2", while "1 through 3" includes the end number, so should output "1 2 3"
* Added SASS solution and output CSS
* Added SASS solution
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator [suggestion](https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979).
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#pullrequestreview-210097979.
* Fixed Markdown syntax
Minor edit
* Updated solution to full solution
Now includes all seed code, plus the changes needed to pass the tests, per @thecodingaviator suggestion https://github.com/freeCodeCamp/freeCodeCamp/pull/34792#discussion_r263731937.
2019-03-09 00:37:52 +09:00
|
|
|
```
|