2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 587d7dbd367417b2b2512bb6
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Create Reusable CSS with Mixins
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 0
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 301455
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: create-reusable-css-with-mixins
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-27 15:45:37 -01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								In Sass, a < dfn > mixin< / dfn >  is a group of CSS declarations that can be reused throughout the style sheet.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-25 09:19:24 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Newer CSS features take time before they are fully adopted and ready to use in all browsers. As features are added to browsers, CSS rules using them may need vendor prefixes. Consider `box-shadow` :
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 05:01:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```scss
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								div {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -webkit-box-shadow: 0px 0px 4px #fff ;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -moz-box-shadow: 0px 0px 4px #fff ;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -ms-box-shadow: 0px 0px 4px #fff ;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  box-shadow: 0px 0px 4px #fff ;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								It's a lot of typing to re-write this rule for all the elements that have a `box-shadow` , or to change each value to test different effects. Mixins are like functions for CSS. Here is how to write one:
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 05:01:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```scss
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mixin  box-shadow($x, $y, $blur, $c){  
						 
					
						
							
								
									
										
										
										
											2020-04-12 05:52:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -webkit-box-shadow: $x $y $blur $c;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -moz-box-shadow: $x $y $blur $c;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -ms-box-shadow: $x $y $blur $c;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  box-shadow: $x $y $blur $c;
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 05:01:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The definition starts with `@mixin`  followed by a custom name. The parameters (the `$x` , `$y` , `$blur` , and `$c`  in the example above) are optional. Now any time a `box-shadow`  rule is needed, only a single line calling the mixin replaces having to type all the vendor prefixes. A mixin is called with the `@include`  directive:
							 
						 
					
						
							
								
									
										
										
										
											2019-05-14 05:01:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```scss
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								div {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @include  box-shadow(0px, 0px, 4px, #fff );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-25 09:19:24 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Write a mixin for `border-radius`  and give it a `$radius`  parameter. It should use all the vendor prefixes from the example. Then use the `border-radius`  mixin to give the `#awesome`  element a border radius of `15px` .
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should declare a mixin named `border-radius`  which has a parameter named `$radius` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(code.match(/@mixin \s+?border-radius\s*?\(\s*?\$radius\s*?\)\s*?{/gi));
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should include the `-webkit-border-radius`  vendor prefix that uses the `$radius`  parameter.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  __helpers.removeWhiteSpace(code).match(/-webkit-border-radius:\$radius;/gi)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should include the `-moz-border-radius`  vendor prefix that uses the `$radius`  parameter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  __helpers.removeWhiteSpace(code).match(/-moz-border-radius:\$radius;/gi)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Your code should include the `-ms-border-radius`  vendor prefix that uses the `$radius`  parameter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(__helpers.removeWhiteSpace(code).match(/-ms-border-radius:\$radius;/gi));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Your code should include the general `border-radius`  rule that uses the `$radius`  parameter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  __helpers.removeWhiteSpace(code).match(/border-radius:\$radius;/gi).length ==
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    4
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-25 09:19:24 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should call the `border-radius mixin`  using the `@include`  keyword, setting it to `15px` .
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(code.match(/@include \s+?border-radius\(\s*?15px\s*?\)\s*;/gi));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --seed--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## --seed-contents--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
									
										
										
										
											2020-05-09 16:31:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style  type = 'text/scss' >  
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  #awesome  {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    width: 150px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: 150px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    background-color: green;
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = "awesome" > < / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-01 01:55:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
									
										
										
										
											2020-05-09 16:31:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style  type = 'text/scss' >  
						 
					
						
							
								
									
										
										
										
											2019-05-01 01:55:22 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @mixin  border-radius($radius) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -webkit-border-radius: $radius;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -moz-border-radius: $radius;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -ms-border-radius: $radius;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    border-radius: $radius;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  #awesome  {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    width: 150px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: 150px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    background-color: green;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @include  border-radius(15px);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = "awesome" > < / div >  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```