Ensuring uniform height for bootstrap navbar links with added bottom border

I have styled my active menu class with a border-bottom.

@media (min-width: 1040px) {
    #rbc-navbar.navbar-default .navbar-nav > li.active {
        border-bottom: 3px solid #56c7ff;
    }
}

However, when hovering over other links, they appear to be at different heights because of the added border at the bottom.

Question: How can I ensure that all links in a bootstrap navbar, when a border bottom is added to one link, are at the same height?

View the Codepen Example here (Note: The code pen now has updated working code)

CSS Styles

#rbc-navbar.navbar-default .navbar-brand {
    color: rgba(255, 255, 255, 1);
}

#rbc-navbar.navbar-default {
    font-size: 16px;
    background-color: rgba(22, 30, 44, 1);
    border-bottom-width: 0px;
}

@media (min-width: 1040px) {
    #rbc-navbar.navbar-default .navbar-nav > li.active {
        border-bottom: 3px solid #56c7ff;
    }
} 

/* Other CSS styles omitted for brevity */

HTML Markup

<div id="rbc-navbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="<?php echo base_url();?>">Riwaka Bowling Club</a>
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-menubuilder">
                <i class="fa fa-bars" aria-hidden="true"></i>
            </button>


        </div>
        <div class="collapse navbar-collapse navbar-menubuilder">
            <ul class="nav navbar-nav navbar-left">
                <li class="active"><a href="/">Home</a></li>
                <li><a href="/about-us">About Us</a></li>
                <li><a href="/contact">Contact Us</a></li>
            </ul>

            <ul class="nav navbar-nav navbar-right">
                <li><a href="">Members Login <i class="fa fa-sign-in" aria-hidden="true"></i></a></li>
            </ul>
        </div>
    </div>
</div>

Answer №1

Check out this CSS snippet:

#rbc-navbar.navbar-default .navbar-nav > li:not(a:hover),#rbc-navbar.navbar-default .navbar-nav > li:not(.active) {
  border-bottom: 3px solid transparent;
}

#rbc-navbar.navbar-default .navbar-nav > li:not(.active) a:hover {
  border-bottom: 3px solid rgba(63, 71, 81, 1);
}

You can view the demo on Codepen here

Answer №2

To easily highlight the active menu item, consider giving all menu items a transparent border and then changing the color of the active one.

@media (min-width: 1040px) {
    #rbc-navbar.navbar-default .navbar-nav > li {
        border-bottom:3px solid transparent;
    #rbc-navbar.navbar-default .navbar-nav > li.active {
        border-bottom-color: #56c7ff;
    }
}

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

I am facing an issue where the weather information is not being displayed even after sending a request to

I'm working on building an app that will provide users with weather data once they input a city. Utilizing the openweathermap.org API for this purpose, I've noticed in my console under networks that an API call is made when the city is entered, b ...

Differences between -webkit- and -moz-transition

My website uses CSS3 transitions and I have noticed that the -webkit- prefix works, but the -moz- prefix does not seem to be working. This is the CSS code I am using: article {z-index: 2; float: left; overflow: hidden; position: relative; -webkit-transit ...

Generate Bootstrap 5 Navbar <li> and <ul dropdown item> dynamically using JavaScript

Requesting assistance I have stored text in the constant.js file as shown below. export const navLinks = [ { id: "manage", title: "Manage", }, { id: "transactions", title: "Tran ...

Guide to positioning text alongside icons with Bootstrap

Struggling to align text next to these icons? Don't worry, we've all been there. Especially with bootstrap - it can be tricky! Can someone please guide me on how to do this? <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstr ...

Shadowy figure in block form

result photo and required modifications The image on the left shows the result I obtained in a browser, while the one on the right displays the desired outcome in Figma. I am struggling with creating a semicircle with a shadow under the coin and implemen ...

Creating a Modern Tooltip Menu with HTML, CSS, and Bootstrap

My goal is to design a menu that opens to the right, similar to a tooltip. I have experimented with different bootstrap techniques, but I am encountering difficulties in including HTML li elements within the tooltip. https://i.sstatic.net/mAHKS.jpg ...

When data is sent to a function through ejs, crucial information becomes accessible on the html page sources

I have encountered an issue where sending data to a function through ejs makes it easily visible in the page source. Could this pose a security risk? Example of code: <a onclick="editDetail('<%=JSON.stringify(data[i])%>')">Edit</ ...

What is the best way to use hasClass in a conditional statement to display text based on the content of a different div element?

Let's say we have the following HTML code: <div>New York</div> Now, we want to add another div like this: <div>Free Delivery</div> How can we achieve this using JavaScript? ...

Adding HTML code directly at the cursor location within a contenteditable element

On button click, I need to insert an element at a specific position within a contenteditable div. Currently, the content is added at the end of the document instead of where the cursor was placed before clicking the button. function append_content() { ...

What is the best method for developing a live text display switcher that works across different pages?

Hello everyone! I am currently in the process of creating a display toggler for my website. I have two separate pages, index.html and toggler.html. In index.html, the "TEXT" is displayed, while toggler.html contains the actual toggler or switch button. Whe ...

Navigating in Angular JS using $location function

I'm facing an issue with navigating between web pages using Angular JS. The first web page is index.html, followed by main.html. Additionally, there is a myscript.js file and style.css, although the latter is not relevant to this problem. My goal is t ...

Can custom HTML elements be designed to function similarly to standard ones?

What is the best way to create a custom HTML element that functions as a link without relying on inline Javascript? For instance: <x-button href="...">...</x-button> Can I develop an element like <x-button> that can accept an attribute ...

Multiple web pages utilizing Angular app/widget

I have successfully built a chat application similar to Google Hangouts. However, I am facing a challenge with the angular app/widget running on other pages when URL's are changed, causing the app to either remain fixed or restart on the new web page. ...

"Exploring the concept of master pages in web development with the combination

Recently, I have been developing a website that functions similarly to olx, displaying ads based on the visitor's location (for example, showing Mumbai ads if the visitor is from Mumbai). Initially, I was planning to create separate pages for each cit ...

Best Way to Enable Push Notifications on Phonegap for iPhone - Top Suggestion

Looking for advice on the most cost-effective way to add push notifications to an HTML5 Phonegap app. I'm a front-end developer with limited xcode knowledge, so I'm considering using a service like Urban Airship. Any recommendations or tips on im ...

Condense a series of items into a single item on Ionic

I have created a form with different sections, each separated by a heading. My goal is to make the items under each heading disappear when it is clicked. Here is an example of what I am trying to achieve: desired layout In the desired design, there is a ...

Guide to incorporating Ember into an existing HTML file

Planning to integrate Ember 2.0 into an existing HTML page and have a few queries regarding this. Is it necessary to build the ember project beforehand? This results in creating appname.js and vendor.js files. Which js files are essential to be included ...

AngularJs FileList Drag and Drop Feature

Being brand new to front-end development, I decided it would be a fun challenge to implement drag and drop functionality on an existing upload page. However, as I began integrating ng-flow (a directive that helps with drag and drop), I encountered difficul ...

Ensure all columns have the same height as the shortest column

While many solutions exist on Stack Overflow for making columns equal height based on the largest content, I am specifically interested in making all columns equal height based on the smallest column. https://i.sstatic.net/Xlcyh.png In this scenario, my ...

JavaScript - The left dropdown menu stubbornly remains visible when clicked in white space, unlike the right dropdown which disappears as expected. Puzzled by this inconsistency

Whenever I click on the selection criteria box, a dropdown menu appears. Clicking on the white space or the data table button makes the drop-down menu disappear, which is good. However, when I perform the same action for 'choose data table,' the ...