title: Angular not obeying css
body: <p>I'm new to Angular and have a question regarding its use of css.  My understanding is that a component obeys only the css within it and is not interfered with by css in any other parts of the program.</p>
  <p>I have a component called <em>MainNavComponent</em>.</p>
  <pre><code>Component({
    selector: 'main-nav',
    templateUrl: './main-nav.component.html',
    styleUrls: ['./main-nav.component.css']
  })
  export class MainNavComponent implements OnInit, OnDestroy {...
  </code></pre>
  <p>There is a slideout menu in the app that contains nav link buttons.  When a button is clicked, its background changes to a different color. Then when you hover over the other buttons, the selected button's background color does not change.  That works for all buttons but one.</p>
  <p>Here is the bad button's html:</p>
  <pre><code>    &lt;a mat-list-item (click)= &quot;customerRoute()&quot; &gt;
          Customer
      &lt;/a&gt;
  </code></pre>
  <p>In the ./main-nav.component.css file, the only css applied to the mat-list-item class is this:</p>
  <pre><code>.mat-nav-list,
  .mat-list-item {
      padding-top: 0 !important;
      font-size: 15px !important;
      color: #444444 !important;
      font-family: &quot;HelveticaNeueW01-55Roma&quot; !important;
  }
  
  .mat-list-item h2.mat-line {
      font-size: 18px !important;
      font-weight: 200;
      line-height: 1.35em;
      color: #263746 !important;
      font-family: &quot;HelveticaNeueW01-45Ligh&quot; !important;
    }
    
    .mat-list-item p.mat-line {
      font-size: 14px !important;
      font-family: &quot;HelveticaNeueW01-45Ligh&quot; !important;
    }
  </code></pre>
  <p>And every button works as intended except one.  I don't see anything there that controls the hover, active, focus or visited events, so I'm at a loss as to why it works on any of the link buttons at all.  My only theory is that I see a bootstrap.js file being imported somewhere.  Could it be controlling the nav link button background color?</p>
  <p>Anyway, I tried to force the bad one to do what the good buttons are doing by adding the following css to the ./main-nav.component.css file:</p>
  <pre><code>.mat-list-item:active {
      background-color: #f1f1f1 !important;
  }
  </code></pre>
  <p>But it had no affect.  I also tried focus and visited.  They also had no affect.</p>
  <p><strong>EDIT</strong></p>
  <p>I've learned that it has something to do with <em>routerLink</em>.  If I change the html to this:</p>
  <pre><code>    &lt;a mat-list-item routerLink=&quot;/Customers&quot; &gt;
          Customers
      &lt;/a&gt;
  </code></pre>
  <p>Then it works correctly.  But then I'm stuck with only one route.  The javascript that the (click) calls causes the route to change depending on certain conditions.  Once the correct route is determined, it then uses the following typescript to navigate to it:</p>
  <pre><code>  customerRoute() {
      this.router.navigateByUrl(this.routeLink);
    }
  </code></pre>
  <p>So something about navigating this way, instead of using routerLink, causes the problem I have described.</p>
  <p>Any suggestions?</p>