The hover effect disappears when the mouse is on the edge

When my mouse is on the bottom border, the hover effect does not work. How can I make the bottom border part of the list container and count as one element? Currently, when the mouse is on the bottom border, the element loses its hover effect.

<style>
 li.nav-item:hover{
 border-bottom:5px solid yellow;
 }
 </style>

 <body style="height:1500px">
  <nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
   <a class="navbar-brand" href="#">Logo</a>
    <ul class="navbar-nav">
     <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
     </li>
     <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
     </li>
    </ul>
  </nav>

Jfiddle

Answer №1

To add the style, just target the a element:

li.nav-item a:hover {
  border-bottom: 5px solid yellow;
}

Answer №2

To prevent the link's height from changing due to the border-bottom and to avoid the navbar toggling on hover, I recommend using the following CSS:

https://jsfiddle.net/qra0f3bk/6/

li.nav-item a:hover{
  position: relative;
}
li.nav-item a:hover::after{
  position: absolute;
  content: '';
  left: 0;
  bottom: 0;
  height: 5px;
  width: 100%;
  background: yellow;
}

Answer №3

By simply including a margin-bottom, the issue should be resolved as well; the hover effect disappears when there is no margin present at the bottom.

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

Exchange information between two selected items

Below is a simplified version of the current code that I am working with: https://jsfiddle.net/2zauty83/8/ Javascript function checkboxlimit(checkgroup) { var checkgroup = checkgroup for (var i = 0; i < checkgroup.length; i++) { checkgroup[i] ...

Guide on retrieving the initial value from HTML and passing it to the controller in AngularJS during page load

<ul> <li ng-init="formData.mdpSunday='5'"> <input ng-model="formData.mdpSunday" name="mdpSunday" type="radio" value="5"> </li> </ul> app.controller(&a ...

Refreshing the page to dynamically alter background and text hues

I'm currently dealing with a website that generates a random background color for a div every time it is refreshed. I have a code that successfully accomplishes this: var colorList = ['#FFFFFF', '#000000', '#298ACC', &ap ...

a div sandwiched between two others

I am trying to nest a <div> within another <div> and center it within the parent. Here is my current approach: <div id="redthing"> <div id="whitebox" > </div> </div> The CSS code I am using is as follows: #red ...

Enhancing the appearance of jQuery datatables using Material Design Lite theme

I came across a helpful codepen demo demonstrating how to create a responsive data table with search filter and pagination. However, this demo is only integrated with Bootstrap. After searching the MDL discussion forum, I couldn't find any existing im ...

The navbar background spans the full width of the screen, with all content contained within minimum and maximum width parameters

Currently, I am working on a fluid website design where I have set specific min-width and max-width values. However, I want the navigation bar background to extend across the entire screen width without being limited by the max width parameter, while still ...

How can I include text input within a select option using angular-material?

I am in the process of developing a form that allows users to input personal information. One feature I would like to include is a dropdown list for phone numbers and fax numbers associated with the individual, giving users the option to choose from thos ...

Deactivate the collapse toggle feature in the footer navigation

I've recently started using bootstrap and I'm having some trouble adding a social nav footer to my portfolio. I've experimented with removing different classes and even tried using the sticky footer feature, but it's not quite what I ne ...

Utilizing window.matchMedia in Javascript to retain user selections during page transitions

I am encountering difficulties with the prefers-color-scheme feature and the logic I am attempting to implement. Specifically, I have a toggle on my website that allows users to override their preferred color scheme (black or light mode). However, I am fac ...

What is the maximum number of data points that can be used in a Scatter plot created

I am currently facing an issue while trying to populate a Scatter plot in JavaScript with decimal values obtained from a MySQL database using PHP. The database contains around 150,000 entries, resulting in 150,000 pairs of decimal inputs for the graph. How ...

Having trouble with animating the background color of an input button using jQuery?

I'm completely confused as to why the background color isn't changing despite investing a significant amount of time into it: <input type="button" class="front-consultation-btn" value="Get A Free Consultation"> <script> $(' ...

Mobile responsiveness issue with menu not functioning as expected

I'm completely new to the world of responsive design with CSS. I recently created a responsive menu that works perfectly when I resize the browser window on my computer. However, when I try to access the site on my phone, the menu is just zoomed out a ...

Issue with submitting Laravel form using post method

I've encountered an issue with a form that is supposed to post a title and a body, but when I submit it, nothing happens. I have included a csrf field and I am using the post method. Despite trying various methods to declare the action and the method ...

ng2-table ways to customize the appearance of a particular row

Hey there, I'm currently new to Angular 2 and working with ng2-table. I've successfully added a table like the one shown here to my website. Now, I'm trying to figure out how to add color to specific rows within the table. Following the ste ...

Build a JavaScript image carousel featuring custom text for each image

I recently completed a tutorial on creating JavaScript image sliders. I have successfully added a text box to display on each image, but now I need the text to be specific for each individual image. The images are sourced from an img folder and are labeled ...

Can someone explain how to implement document.querySelector in TypeScript within the Angular framework?

I am tackling the task of creating a login/register form that allows users to switch between the two forms with the click of a button. The goal is to only display one form at a time. Initially, I implemented this functionality in a basic HTML file and it w ...

Progress bar displaying during Ajax request

I'm currently working on an Ajax request that uploads images to the Imgur API and I want to implement a progress bar to show users the upload progress. I found some guidance in this thread, but it seems to display only 1 and stop working. This is the ...

Sending a rendered HTML template via email using Flask

I'm currently using Flask to generate an API and passing the data through a rendered template in order to create charts on an HTML page using a Python script. Could you please advise me on how I can send the rendered HTML page, along with all the cha ...

Switching Images with Rounded Border on Hover Effect

After carefully crafting a rounded box/button and slicing its first corner, the middle bar (which repeats horizontally to adjust the width of the button text/content), and the last corner, I utilized the following markup: <div id="left-corner"></ ...

Unusual Display of Mantine Radio Button

I am currently using Mantine v7.0.0 in combination with Next.js v13.5.2 and Tailwind v3.3.3. In my setup, when I create <Radio /> elements, the svg of the element is appearing separately from the radio button instead of replacing it. This issue can b ...