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

Cosimo Scarpa
Cosimo Scarpa
14,047 Points

How manage the selection of a specific class in CSS or SASS

Hi there, I would like select a specific class or ID inside my code but I have some issue. Basically what I'm trying to do is this:

  • hover .bg1
  • change the color of #eye

This is the HTML code

<div class="main">
  <div id="A" class="bg1"></div>
    <div id="B"class="bg2"></div>
    <div id="C" class="bg3"></div>
    <div id="D" class="bg4"></div>
    <div class="container">
      <div id="eye"></div>
   </div>
</div>

I'm using SCSS in my project.

.bg4 {
  &:hover .container {
    #eye {
      background: red;
    }
  }
}
Charles Kenney
Charles Kenney
15,604 Points

Cosimo,

What you're trying to do won't work because the class .bg4 is a sibling to .container. The code you have written selects a .container element which is a dependent of .bg4 (child) while the mouse is hovered over .bg4. This would only work if the container div was a child of .bg4.

1 Answer

Cosimo Scarpa
Cosimo Scarpa
14,047 Points

Charles Kenney thank you for your answer. You are right but also for some reason I wasn't able to select .bg1 class. I mean the reason it was because the class has 'z-index: -1'. I also tried just to hover .bg1 to change the colour but without results.

By the way the correct code is

.bg1 {
  &:hover ~ .container #eye {
    background: red;
  }
}