Issue with Angular 12: Button Styles malfunction when the first Button is activated

I recently created a navigation bar for a website with 6 buttons that change appearance when the current route is active. However, I encountered an issue where clicking on the top button caused the CSS styling of the following buttons to not work as expected. This problem only occurs with the very top button and when I remove it, the issue persists with the next button in line. The other 5 buttons function correctly.

Below is the code for the navigation bar:

.container {
    float: right;
    background-color: rgb(199, 199, 199); 
  }

.btn-nav {
    display: inline-block;
    background: transparent;
    border: 1px solid black;
    height: 60px;
    width: 60px; 
    margin: 11px;
    border-radius: 15px;
    cursor: pointer;
  }
  
  .active-link {
    display: inline-block;
    background: white;
    border: 1px solid black;
    /*padding: 5px 5px;*/
    height: 60px;
    width: 60px; 
    margin: 11px;
    border-radius: 15px;
  }

.img {
  height: 45px;
  width: 45px;
  margin-top: 5px;
}
<div class="container">
        
        <button  routerLink="/filtering" 
                routerLinkActive="active-link"
                #link="routerLinkActive"
                class="btn-nav"
                style="align-content: center;"
                [class.btn-nav]="!link.isActive"><img src="/assets/icons/1.png" alt="filtering operation Icon" class="img"></button>
        <br>
        <button routerLink="/cleaning" 
                routerLinkActive="active-link"
                #link="routerLinkActive"
                class="btn-nav"
                style="align-content: center;"
                [class.btn-nav]="!link.isActive"><img src="/assets/icons/2.png" alt="cleaning Icon" class="img"></button>
        <br>
        <button routerLink="/hood" 
                routerLinkActive="active-link"
                #link="routerLinkActive"
                class="btn-nav"
                style="align-content: center;"
                [class.btn-nav]="!link.isActive"><img src="/assets/icons/3.png" alt="Hood Icon" class="img"></button>
        <br>
        <button routerLink="/?" 
                routerLinkActive="active-link"
                #link="routerLinkActive"
                class="btn-nav"
                style="align-content: center;"
                [class.btn-nav]="!link.isActive"><img src="/assets/icons/4.png" alt="archive Icon" class="img"></button>
        <br>
        <button routerLink="/?" 
                routerLinkActive="active-link"
                #link="routerLinkActive"
                class="btn-nav"
                style="align-content: center;"
                [class.btn-nav]="!link.isActive"><img src="/assets/icons/5.png" alt="Menu Icon" class="img"></button>
        <br>
        <button routerLink="/home" 
                routerLinkActive="active-link"
                #link="routerLinkActive"
                class="btn-nav"
                [class.btn-nav]="!link.isActive">home</button>
        <br>
</div>

Answer №1

To fix the issue, you can either remove the

[class.btn-nav]="!link.isActive"
for each button or add margin: 11px; to the .active-link class.

<button  routerLink="/filtering" 
      routerLinkActive="active-link"
      #link="routerLinkActive"
      class="btn-nav"
      style="align-content: center;">
   <img src="/assets/1.jpg" alt="filtering operation Icon" class="img"> 
</button>

https://i.sstatic.net/oNHj8.png https://i.sstatic.net/MyRwk.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to retrieve JavaScript variables within JSP files?

What is the best way to interact with Javascript variables within JSP code? ...

Utilizing Bootstrap exclusively within a designated container div

Incorporating bootstrap into my TYPO3 frontend plugin has been beneficial, but I am looking to apply it selectively within a specific div. This way, the class without_bootstrap remains unaffected by any changes made by the bootstrap classes. Consider this ...

Having trouble locating an element using Selenium?

I'm attempting to extract the price of a flight from Google Flights website using Selenium, but I am unable to locate the specific element on the page. Even after scraping the entire page, the element remains elusive. It has been suggested that it may ...

How to make an input blur in Angular 2 when a button is clicked?

Is there a way to blur an input field by pressing the return button on a mobile native keyboard? Here is an example: <input type="text" #search> this.search.blur() //-- unfocus and hide keyboard ...

Trigger a class method in an event using Angular with Typescript

I am completely new to TypeScript and Angular, and I am attempting to create a basic drawing component on a canvas. However, I have reached a point where I feel lost and confused about my code. The concept of "this" in TypeScript has been a major stumbling ...

What is the process of enabling a concealed input feature?

I have a straightforward script that enables users to input a value into a form. These values are then combined to create a URL, which is used to load a page within an iframe. Everything works fine... but I'm having trouble figuring out how to hide t ...

A tag that does not adhere to the background color's rgba opacity restrictions

Can you believe what's happening to me? Check out this code snippet. I'm trying to apply an rgba color to my a tag, but it's acting like an rgb color instead of the intended rgba. The text background is solid, but the rest of the background ...

Custom Jquery function is failing to position divs correctly within ajax-loaded content

I recently coded a custom function that efficiently positions absolute divs within a container by calculating top positions and heights: $.fn.gridB = function() { var o = $(this); //UPDATED from var o = $(this[0]); o.each(function() { var ...

Can classes be encapsulated within a NgModule in Angular 2/4?

Looking to organize my classes by creating a module where I can easily import them like a separate package. Take a look at this example: human.ts (my class file) export class Human { private numOfLegs: Number; constructor() { this.numOfLegs = 2 ...

Strategies for quickly landing in top Google search results

I run a website for classified ads... Whenever users post a new ad, it gets automatically included in our dynamic sitemap (xml). Our sitemaps were submitted to Google via Webmaster Tools about two months ago. While some of the ads are indexed, it is tak ...

Unsuccessful PHP conversion of numbers to words

Kindly take note that the PHP code provided below is used to convert a numerical amount into words. It functions properly for integers like 5250, however, when it encounters a decimal number, it produces inaccurate results. Example: for 450 = four hundred ...

Directive for masking input values

I am in need of an input that adheres to the following format: [00-23]:[00-59] Due to the limitations of Angular 2.4, where the pattern directive is unavailable and external libraries like primeNG cannot be used, I have been attempting to create a direct ...

Issue with styling of ActionLinks and regular anchor links in MVC due to their small size

I recently encountered an issue that I couldn't resolve using an ActionLink, so I had to resort to using a regular hyperlink. Both links are styled similarly on the page due to passing the same css conditions, but I observed two key differences betwe ...

Tips for adding npm modules in StackBlitz?

Is it possible to install npm packages for Angular on StackBlitz without a terminal? I'd like to know the process. ...

Trigger jQuery to play audio files

Something seems off with this code. The audio file isn't playing when the webpage loads. $(document).ready(function() { var audioElement = document.createElement('audio'); audioElement.setAttribute('src','content/aud ...

Navigation bar in HTML positioned on the right side of the webpage

My goal is to have a navigation bar on the right side of the page, taking up 250px, while allowing the main content to naturally adjust its size based on the window dimensions. I do want the main content to appear before the navigation in the HTML structur ...

Utilizing AngularJS2 with PHP on Apache server

Starting my journey with AngularJS today. Following tutorials on AngularJS version 2 using JavaScript. Node.js is a requirement, but my current development environment includes PHP, MySQL, and Apache (Xampp). I am curious if it is possible to develop and ...

Truncate text on a dynamic button positioned above a fluid container

Looking for a CSS-only solution to manage text within an image-defined box? The challenge is to place a button in the center if the text is shorter than the image, or cut it with ellipsis if longer. Also, the text should not exceed the box width. Any ideas ...

How can I eliminate a class when the scrollTop() position matches a specific div element?

I am trying to implement a script that will allow me to scroll to my navigation and then change the class of the navigation, however, it is not working as expected. $(window).scroll(function() { if ($(window).scrollTop == $('.menu_nav').offs ...

stop cascading style sheets from being overwritten

In my ASP.NET web forms project, I am utilizing Telerik controls. The Problem In one instance, I need to retrieve HTML data from the database, which includes a lot of CSS, images, and HTML content. Here is an excerpt of my code: <telerik:RadLabel ...