The height of the div unexpectedly adjusts after content is displayed on hover

Within my anchor tag, there are two elements: a fontawesome Icon and a hidden span that only appears when the anchor is hovered over. The problem arises on my website when the hidden span is displayed inline causing the parent anchor to increase in height. This occurs regardless of text size adjustments such as reducing the font-size or line-height of the span.

I have attempted to isolate the code for the issue but have been unable to replicate it. Here is the code nonetheless:

:root {
    --darkblack: #000615;
    --black: #0B1721;
    --lightblack: #141B37;
    --yellow: #F7C921;
    --darkyellow: #a28b2a;
    --cyan: #21B7FF;
    --darkcyan: #1c7eaf;
    --magenta: #FF217D;
    --darkmagenta: #531a3b;
}

.nav {
  align-items: flex-end;
}

.nav-pills .nav-link {
  width: fit-content;
}

.nav-pills .nav-link.active {
   color: var(--black) !important;
   background-color: var(--cyan);
 }

.nav-pills .nav-link:not(.nav-link.active) {
  color: var(--cyan) !important;
  cursor: pointer;
}

.nav-pills .nav-link:hover > .nav-title {
  display: inline !important;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aac8c5c5ded9ded8cbdaea9f849a8498">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="row">
  <div class="col-10">
    
  </div>
  <div class="col-2">
    
    <ul class="nav nav-pills flex-column mb-auto">
    <li class="nav-item">
        <a href="#" class="nav-link active" aria-current="page">
            <i class="fa-solid fa-book"></i>
            <span class="d-none nav-title">Test</span>
        </a>
    </li>
    <li>
        <a class="nav-link" data-id="tags">
            <i class="fa-solid fa-tags"></i>
            <span class="d-none nav-title">Tags</span>
        </a>
    </li>
</ul>
    
  </div>
</div>

I meticulously reviewed each CSS rule related to the icon, text, and span to identify any rules causing the issue, but disabling them did not resolve the problem. The only rule that had an impact was

.fa-classic, .fa-regular, .fa-solid, .far, .fas {
  font-family: "Font Awesome 6 Free";
}

This rule is sourced from the FontAwesome library, and removing it would break the icon functionality. I am struggling to pinpoint the root cause of this issue. Any insights would be greatly appreciated.

For reference, here is a visual depiction of the problem on my site: https://i.sstatic.net/KPSYskRG.gif

Answer №1

Adjusting the height of an element is not working properly for me, but you can set a specific height to prevent it from changing with the context of the element. For instance:

.nav-link{
           height: 25px; 
          /* other styles */
         }

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

Modify the styling of the main webpage using the iframe

Can the CSS of a parent page be modified from an iframe when the parent page and iframe are hosted on separate domains? ...

The POST request did not yield an HttpResponse object; instead, it returned None

When I submit a selection from a dropdown form to views as a POST request, and then use this selection to query data from Django, I encounter an issue while trying to map Django models data to Highcharts following this approach. The error message "the view ...

Ensure that the main div remains centered on the page even when the window size is adjusted

Here is the code snippet: <div id="root"> <div id="child1">xxxx</div> <div id="child2">yyyy</div> </div> CSS : #root{ width: 86%; margin: 0 auto; } #root div { width: 50%; float: left; border: ...

Utilizing Angular to Handle Undefined Variables in String Interpolation

Seeking a way to showcase data obtained from an external API on a webpage using Angular's string interpolation. If no data is retrieved or is still pending, the aim is to display 'N/A'. An attempt was made following this method, but encoun ...

Outlook's Dilemma with Background Images

I'm currently developing a new newsletter template, and I've encountered an issue with background images not displaying properly in Outlook. The code below illustrates the desired layout: <table style="width: 600px;" align="cent ...

What is the best method for parsing information from the HTML source code of a specific tab on a webpage?

I have tried various methods mentioned in different responses, such as testing with different user agents (Chrome, Safari etc), and fetching HTML directly using HTTPClient and BufferedReader, but unfortunately none of them seem to be effective. How can I ...

What is the best way to align Bootstrap icons in the middle of buttons?

Currently, I am incorporating bootstrap icons into my design. Feel free to explore the provided DEMO. It showcases the issue of the bootstrap icons not aligning in the same line as the text inside the button. I am seeking advice on how to centralize the i ...

Tips for incorporating css @keyframes within a cshtml file:

My cshtml page includes a Popup that I created, but I encountered an issue with keyframes. When I tried to use it without keyframes, the fade effect was lost. I am looking for a way to fix my @keyframes. (I tested the code on Chrome and Opera) I found the ...

issue with animation occurs when the value changes while the setTimeout timer is still running

function wallpaperMediaPropertiesListener(event) { // reset animation test.stop(true); test.css('margin-left', 0); // set song title. test.text(event.title); var testWidth = test.outerWidth(); // clone text ...

Implementing a fixed search bar in Angular for a dropdown selection using mat-select

I'm currently utilizing a mat-select widget from Angular-Material in my application To enhance user experience, I am adding a search bar at the top of the select dropdown for filtering options: <mat-select placeholder="Select a store" ...

"Choose between displaying the Bootstrap Column consistently in a vertical orientation or a horizontal orientation

I'm just diving into the world of HTML/CSS and currently experimenting with Bootstrap Studio for a project. My focus is on creating an 'About' section for a webpage, where I've structured four rows each containing two columns as follows ...

The positioning of drawings on canvas is not centered

I'm facing an issue while attempting to center a bar within a canvas. Despite expecting it to be perfectly centered horizontally, it seems to be slightly off to the left. What could possibly be causing this discrepancy? CSS: #my-canvas { border: ...

HTML 5 functions properly when loaded directly as a .html file, but encounters issues when hosted on either a Django or Node

I'm having trouble getting a video to play on a webpage. Initially, I followed a standard example I found online by using the following code: <video src='video.mp4' controls></video> When I open the .html file in Safari and dou ...

Launch a popup modal box from within an iframe and display it in the parent window

I'm facing a challenge with opening a modal dialog in the parent page from an iframe. The button to open the modal dialog resides in the iframe, but the modal div is located on the parent page. Here's a snippet of my parent page: <html xmlns ...

Difficulties encountered with CSS transitions when using the background

I stumbled upon some interesting examples on Stack Overflow about the fade effect on link hover. Curious, I decided to try it out myself and created this JSFiddle. <div class="fade"/> .fade { -o-transition: 0.3s; -moz-transition: 0.3s; -khtml-tran ...

The hyperlink does not display any text indicating an issue in the Wave accessibility evaluation tool

On my HTML page, there is a certain code snippet: <a href="example.com"><i class="myclass"></i></a> <a href="http://www.google.com" class="cart visible-xs"><i class="t-icon t-icon-cart-xs-2"></i></a> Des ...

Enhance your images with a hover zoom effect while viewing an overlay on top

Is there a way to make an image still zoom in on hover even when it has an overlay using CSS? I am currently working with Bootstrap 5.2 Thank you in advance. .trip-card { position: relative; } .trip-card img { border-radius: 30px; } .overlay { ...

Executing 'npm start' to launch an HTML file along with a CSS stylesheet - A step-by-step guide

As a newcomer to the world of coding, I've found that asking questions on platforms like Stack Overflow enables me to connect with fellow developers. I usually code using VS Code and rely on the "live server" extension to quickly test my code. Howeve ...

The dominance of CSS specificity in favor of the flex property compared to flex-basis

Is there a specificity among CSS properties that affects how styles are applied? I've been experimenting with flexbox and encountered an interesting scenario: The second selector .flex-basis-5 is added dynamically via JavaScript based on certain con ...

Is the availability of XMLHttpRequest constant?

When using XMLHttpRequest to retrieve data from the server with Javascript, is it necessary to include conditional checks for the specific browser being used? Is the code snippet below considered standard practice when working with XMLHttpRequest? if (w ...