The CSS transition timing seems to be malfunctioning as not all elements are smoothly transitioning, specifically the text within the li and anchor tags is not

I'm attempting to achieve a smooth transition effect on a navbar when hovering over it, changing the color from one to another. The navbar contains a list of words, but I am encountering an issue where during the transition, there is a quick flash (appearing like a white color block) around the ul/li/a elements, disrupting their transition timing. Oddly, everything else in the d-flex div transitions as expected. When hovered upon, the background color of the navbar should transform into white and the text into black with a .25s transition. This code snippet is written in Angular 8.

Here's my code:

.navbar-default .navbar-nav>li>a {
  padding-top: 35px;
  padding-left: 0;
  padding-right: 0;
  margin-left: 15px;
  margin-right: 15px;
  padding-bottom: 0;
  min-height: 22px;
  font-weight: 600;
  font-size: 12px;
  color: white;
  line-height: 1.2em;
  text-transform: uppercase;
  display: block;
}

.d-flex {
  height: 80px;
  margin-right: auto;
  background-color: rgba(0, 0, 0, 0.5);
  transition: all 0.25s;
}

.d-flex:hover,
.d-flex:hover li,
.d-flex:hover a {
  background-color: white;
  color: black !important;
}
<nav class="navbar-default">
  <div class="container-fluid no-transition">
    <div class="d-flex">
      <div class="navbar-collapse collapse" [ngClass]="{'in': !menuCollapsed}" [attr.aria-expanded]="!menuCollapsed">
        <ul class="nav navbar-nav">
          <li *ngFor="let link of navLinks" class="{{link.color}}" [ngClass]="{'active': activeTab === link}">
            <a (onClick)="activateTab(link)" href="{{link.path}}" target="{{link.target}}">{{link.label}}</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</nav>

Answer №1

It's important to carefully consider which selectors and styles you apply to each element. For instance, the background should only change on the d-flex where it is defined.

Answer Code:

.navbar-default .navbar-nav>li>a {
  padding: 35px 0 0 0;
  margin: 0 15px;
  min-height: 22px;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.2em;
  text-transform: uppercase;
  display: block;
}

.d-flex {
  height: 80px;
  margin-right: auto;
  background-color: rgba(0, 0, 0, 0.5);
}

.d-flex,
a,
li {
  transition: 0.25s;
  color: white;
}

.d-flex:hover.d-flex {
  background-color: white;
  transition: 0.25s;
}

.d-flex:hover li,
.d-flex:hover a {
  color: black;
  transition: 0.25s;
}
<nav class="navbar-default">
  <div class="container-fluid no-transition">
    <div class="d-flex">
      <div class="navbar-collapse collapse" [ngClass]="{'in': !menuCollapsed}" [attr.aria-expanded]="!menuCollapsed">
        <ul class="nav navbar-nav">
          <li *ngFor="let link of navLinks" class="{{link.color}}" [ngClass]="{'active': activeTab === link}">
            <a (onClick)="activateTab(link)" href="{{link.path}}" target="{{link.target}}">{{link.label}}</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</nav>

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

Animated the height of a rectangle during initial loading and when the mouse hovers over or leaves

Being new to Vue.js, I am looking to create a simple animation on component load for the first time. You can find my initial code here: <template> <div id="app"> <div class="rect" /> </div> </template ...

Learn how to smoothly scroll to the top of a div by clicking on a team name

CSS Code .hover-div { position:absolute; margin-top:-150px; visibility:hidden; transition:all 0.5s linear 0s; } .team_hover:hover + .hover-div { margin-top:0px; visibility:visible; } .hover-div:hover { margin-top:0px; visi ...

How can you make the second block element in a pair stretch to fill the parent element?

I'm currently struggling to make the "rightcol" in the "wrapper" of my data-entry form fill the remaining space next to the second column. Despite successfully displaying the child elements properly, whenever I use the border-bottom attribute, the bor ...

Is there a way to delay the start of this until a legitimate answer is provided in a pop-up window?

Is it possible to delay the loading of this content until a prompt box is answered with a valid response, and have it only appear once a month? Do I need anything beyond JS and HTML for this functionality? <script language="javascript"> function ...

The Intersection Observer fails to function properly with images

I recently discovered that images require different intersection observer code than text in order to function properly. After making the necessary changes to the code, my intersection observer is behaving quite oddly. As I scroll down, the image stays hidd ...

Utilizing Angular and ASP .Net Web Api in conjunction with Plesk hosting platform

I have successfully created a website using Angular and .NET Framework 5.0. I was able to publish the Angular portion on Plesk and it is working correctly, but I am facing challenges in publishing the .NET Framework app and connecting it with Angular. ...

Update the hover effect specifically for mobile devices

.hovereffect a.info,.hovereffect h2{text-transform:uppercase;color:#fff} .hovereffect{float:left;position:relative;cursor:default} .hovereffect .overlay{position:absolute;top:0;left:0;opacity:0;background-color:none;-webkit-transition:all .4s ease-in-out ...

Utilizing UIWebView for dynamic HTML templating

Greetings! I am seeking to develop an HTML template (either internal or external) for the data received from an XML request. The following code has been functioning smoothly thus far: NSString* desc = [screenData.jsonVars objectForKey:@"descriptionTXT ...

The inclusion of routes from an API request in Angular does not seem to be functioning properly when

Currently, I am embarking on a project that requires the loading of specific routes from a CMS using an API request. Upon executing the code snippet below with "ng serve -o," all routes function properly; however, once I run "npm serve:ssr" following a bu ...

Tips for clearing a saved password in a browser using Angular.js and Javascript

There is an issue with the password and username fields in my Angular.js login page. When a user clicks on the 'remember me' option in their browser after logging in, the saved username and password are automatically displayed in the respective f ...

Retrieve a collection of CSS classes from a StyleSheet by utilizing javascript/jQuery

Similar Question: Is there a way to determine if a CSS class exists using Javascript? I'm wondering if it's possible to check for the presence of a class called 'some-class-name' in CSS. For instance, consider this CSS snippet: & ...

What steps do I need to take in order to create a histogram with perfect symmetry?

I am looking to create a unique JavaScript program that can generate a symmetric histogram resembling the image provided below: This program will prompt the user to input the number of bars they want to display and specify the character used to draw the b ...

Ways to assign a default value to a radio button using a mock JSON dataset

As a beginner in AngularJS2, I am looking to resolve an issue where the checkbox is automatically checked when retrieving values from a mock JSON file. Can someone please help me? <div class="form-row"> <div class="formHeading">Skills *< ...

I encountered an issue with uploading an image file in Angular and am currently experiencing an error

media.components.html <div class="row justify-content-center" style="position:relative;top:105px;"> <div class="col-md-6"> <!-- form company info --> <div class="card card-outline-secondary"> <div ...

Tips for rotating a responsive table on a mobile device's screen

I am currently managing a blogger website that features an HTML table on the homepage. I am struggling with making this table responsive for mobile devices, and I would like it to look similar to the image provided below. Can someone guide me on how to ach ...

When it comes to printing, the @Media CSS rule

I have a specific structure on my HTML page: <html> <head></head> <body> <nav> .... navigation menu </nav> <div> <div></div> <div class="to-print"> <h2>Th ...

How to ensure a list item remains in a fixed position when resizing the window

Imagine a scenario where there is an unsorted list within a resizable div element. The list is set up horizontally and aligned to the right, with one item designated as "special" and given the id="pinned". Using only CSS, can you keep the #pinned item in ...

What is the best way to distinguish between relative blocks and convert them to absolute positioning?

What is the best way to locate relative blocks and convert them to absolute position while keeping them in the same place? Is this something that can be achieved using JavaScript or jQuery, or is it simply not possible? Thank you very much. ...

Sorting outcomes based on HTML file

Attempting to narrow down results based on certain criteria within a large HTML file. Unsure if my query is attainable, but it never hurts to inquire. Currently immersed in a browser game featuring a vast map measuring 100x100, with each pixel representing ...

Tips for aligning text alongside ons-select elements

I am working with the following HTML snippet: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css"> <link rel="stylesheet" href="https://u ...