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 trialhadleylambeth
13,946 PointsWhy Doesn't This Work In Sass?
I have an icon and a span tag that when you hover over them the icon changes to one color and the span tag does something else. Pretty simple and it works just fine.
I also need to create an active state class that can be applied after someone has clicked on this icon. My problem is that adding the active class below doesn't work. I had to copy and paste all of the same code out into a new class in order for it to work, but I don't understand why.
My reasoning is that this code will just compile to look for any element with a class of .action and .action-active and then will perform the same css that I get when I hover. What am I missing here?
.action {
display: block;
color: inherit;
&:hover, &:focus, .action-active {
.fa-check {color: $green;}
.fa-location-arrow {color: $blue-light;}
.fa-heart-o {
color: $pink;
&:before {content: "\f004";}
}
span {
color: inherit;
font-weight: bold;
}
}
}
Here is the html
<div class="actions text-md">
<div class="actions-container">
<a class="action action-active">
<i class="fa fa-check"></i>
<span>Been</span>
</a>
</div>
</div>
hadleylambeth
13,946 PointsHi thanks for getting back to me. I just updated the html above to show how it is being used. I don't have a workspace this is something I made at work. It is just on an a tag and the hover works but the active-action class does nothing unless I break it out into it's own class.
1 Answer
Himanshu Chopra
3,055 PointsHello Handley! I guess you are missing & operator for your .action-active class. If your action-active class adds on the same element which you click(I mean if your .action & .action-active class is on the same element the you need to use & operator.
.action {
display: block;
color: inherit;
&:hover, &:focus, &.action-active {
.fa-check {color: $green;}
.fa-location-arrow {color: $blue-light;}
.fa-heart-o {
color: $pink;
&:before {content: "\f004";}
}
span {
color: inherit;
font-weight: bold;
}
}
}
Is that what you are looking for? Let me know If I am misunderstanding something. would love to help you :)
hadleylambeth
13,946 PointsAwesome! Thank you so much that worked. I had thought the & operator was only for pseudo selectors.
Himanshu Chopra
3,055 Pointsoh okay . You are most welcome Hadley :)
Himanshu Chopra
3,055 PointsHimanshu Chopra
3,055 PointsHello! May I know on which element you are adding action-active class & can you share your workspace if that's okay with you?