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 trialjlampstack
23,932 PointsUsing interpolation as a @mixin() parameter in SASS
Is it possible to use interpolation for a mixin parameter? For example lets say we want to create a parameter for a background image. Here is an example of what I'm trying to do.
-
Path to images
$path-img : "../img/";
-
Create Mixin.... Note use of interpolation
@mixin myMixin($img) { height: 300px; width: 300px; background: url('#{$path-img}#{$img}') no-repeat center; background-size: cover; }
-
Include mixin
.some-div { @include myMixin($img: picture.jpg); }
1 Answer
Flor Antara
12,372 PointsHi jaycode,
Sure it is possible.
Just make sure you define your image with quotes, so the path is correctly formatted.
Like:
@include myMixin( $img: "picture.jpg" );
jlampstack
23,932 Pointsjlampstack
23,932 PointsGreat! It works. The quotes around "picture.jpg" made the difference.
I was confused because without the .jpg you don't need the "quote" marks around picture.