Solution Explanation SASS - Create Reusable CSS with Mixins

Tell us what’s happening:

I solved this by going off of the hints in this lesson but I absolutely don’t understand the concept of mixin and why the syntax is written as it was in the examples/solution. Can someone explain this to me like I am 5?

Your code so far

<style type='text/scss'>

@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>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36

Challenge Information:

SASS - Create Reusable CSS with Mixins

It probably makes a little more sense if you know some JS or some other programming language. Although, CSS does have functions.

It lets you create a block of code or a function (if you need to supply it an argument) and when you “include” the mixin it is like it copy/paste that code to that place where you include the mixin.

Hi @raven1177

In addition to what @lasjorg wrote, this part is creating a template for the border-radius styling property. $radius can then be replaced with whatever value you want.

The @include line then sets the value to 15px

So the border-radius for #awesome is now:

 -webkit-border-radius: 15px;
  -moz-border-radius: 15px;
  -ms-border-radius: 15px;
  border-radius: 15px;

You can reuse the template you created, with any value you choose.
This will save you from having to retype similar code.

Happy coding