Multiple classes on the same parent element do not work when used simultaneously: BEM
P粉208469050
P粉208469050 2023-09-10 17:58:49
0
1
591

I have two classes on the header: .header-container and a theme class like solid-green or solid-blue.

The current markup works fine in applying related theme styles, but I want to use BEM, so all CSS should be wrapped in a header-container class:

.header-container {
  // all component styles
}

.top-banner {
  height: 70px;
}

.main-banner {
  height: 140px;
}

.solid-green {
  .top-banner {
    background-color: green;
  }
  
  .main-banner {
    background-color: lightgreen;
  }
}

.solid-blue {
  .top-banner {
    background-color: blue;
  }
  
  .main-banner {
    background-color: lightblue;
  }
}
<header class="header-container solid-green">
  <div class="top-banner">Top banner</div>
  <div class="main-banner">Main banner</div>
</header>

However, when I wrap the CSS with the header-container class, the theme class no longer works. Can anyone tell me where I'm going wrong?

P粉208469050
P粉208469050

reply all(1)
P粉510127741

.header-container {
  .top-banner {
    height: 70px;
  }
  
  .main-banner {
    height: 140px;
  }

  &.solid-green {
    .top-banner {
      background-color: green;
    }
    
    .main-banner {
      background-color: lightgreen;
    }
  }
  
  &.solid-blue {
    .top-banner {
      background-color: blue;
    }
    
    .main-banner {
      background-color: lightblue;
    }
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template