Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Can someone help me with this code challenge?

I have no idea how to even set this one up.

http://teamtreehouse.com/library/advanced-mixin-arguments

Chris Shaw
Chris Shaw
26,676 Points

Hi Leon,

Which task are you have trouble with?

The very beginning of the problem.

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Leon;

Greetings!

So, here is Task 1, let's walk through it step by step...

Task 1

Create a mixin called square that takes two arguments - one called "size" that will set the height and the width, and one called "color" that will set the color of a 1px solid border.

1. Create a mixin called square -> @mixin square

2. ...that takes two arguments -> @mixin square(arg1, arg2)

3. ... -one called "size" that will set the height and width:

@mixin square($size, arg2) {
    height: $size;
    width: $size;
}

4. ...and one called "color" that will set the color of a 1px solid border.

@mixin square($size, $color)
{
    height: $size;
    width: $size;
    border: 1px solid $color;
}

Now that we have this mixin, who cares? What does it allow us to do, right? Well, let's say that we want to create a bunch of different squares in our CSS. Now we could write out the code each and every time in CSS like this:

.square_1 {
    height: 20px;
    width: 20px;
    border: 1px solid red;
}

.square_2 {
    height: 10px;
    width: 10px;
    border: 1px solid blue;
}

And so forth. Or, for each of our separate items, square classes in this case, in Sass we can do:

.square_1 {
    @include square(20px, red);
}

.square_2 {
    @include square(10px, blue);
}

Both of those will produce the same code in CSS, but there is much less code to type using Sass. Not too much of a savings here, but what if you were producing 100 or 1000 square classes? In addition to the savings in typing, think of how much simpler it will be if you want to increase the border to 5px in all of your squares. You would only have to make the change in the @mixin square and not all 1000 separate pieces of code.

Hope it helps,

Ken

Ken Alger
Ken Alger
Treehouse Teacher

I would again point you to the SassMeister site to see your code "in-action" for the series of tasks in this challenge. If you write your code in the SCSS section of the screen you can see almost immediately what the CSS output is and if there are any errors. You can then compare that with the output the task is calling for to get a check on your answer.

Just a thought. :smile:

Ken

Okay, I got number two by myself, however I am having trouble with number three.

By the thanks for the link I actually plan on using at one point.

Here is my code

@mixin square($size, $color) { height: $size; width: $size; border: 1px solid $color; }

$color: black;

.box { @mixin include square ($size, $color) { height: 10px; width: 10px; border-color: red; } }

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Leon:

For Task 2 to have a color selected by default, you want to put the $color: black statement inside the @mixin definition, like so:

@mixin square ($size, $color: black) {
// rest of the code here
}

That way when the mixin is included it will default to black automatically. Your code works for the challenge, but if the $color variable gets redefined somewhere else, the mixin won't default to black.

Task 3

Define a box class. Use the square mixin to give it a height and width of 10px, and set the border to red.

To include the mixin you need an @include statement along with the values for the different arguments, so inside the box class, in this case we need a statement of:

@include square(10px, red);

That's it! Through the magic of Sass that one simple statement will produce the height, width, and border-color properties with 10px and red as values, respectively.

Ken

Do you think you can help me with number four?

Ken Alger
Ken Alger
Treehouse Teacher

You bet, what is confusing you with Task 4?