"Create a sleek underline effect for a Bootstrap 4

Can someone please assist me with an issue I'm facing? The underline in my navbar is not working as expected. Here are my HTML and CSS files: https://jsfiddle.net/57fd6yf5/1/ I am trying to make the cursor activate underlining only under the menu items, not under the logo. I suspect there may be a problem in the CSS file.

HTML:

      <nav class="navbar navbar-expand-md navbar-light bg-dark">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item active">
          <a class="nav-link" href="#">HOME</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">O MNIE</a>
        </li>
        <li class="nav-logo">
          <a href="#"><img id="logo-navbar" src="images/logo.png" width="60px" height="60px"></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">PORTFOLIO</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">KONTAKT</a>
        </li>
      </ul>
    </div>
  </nav>

CSS:

.nav-link{
  font-size: 20px;
}
.nav-item{
  padding: 15px 30px;
}
.nav-logo{
  padding: 10px 10px
}

.navbar-collapse {
  justify-content: center;
}
.navbar-light .navbar-nav .active::after{
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  width: 100%
  content: " ";
  color: #F4C127;
  border-bottom: 5px solid #F4C127;
}
.navbar-nav > li {
  float: left;
  position: relative;
}

Answer №1

To ensure that the border-bottom appears under the active link item, you can utilize the following css rule:

.navbar-light .navbar-nav .active>.nav-link {
    border-bottom: 5px solid #F4C127;
}

Conversely, if you prefer the border to be displayed at the bottom of the entire navbar, it is important to include the missing ; in the width: 100% section of your existing css rule (as noted by @ZimSystem).

Answer №2

In order to update your css code, make sure to use the class

.navbar-light .navbar-nav li.active

.navbar-light .navbar-nav li.active::after{
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  width: 100%;
  content: " ";
  color: #F4C127;
  border-bottom: 5px solid #F4C127;
}

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

Tips for synchronizing JavaScript rendering time with Python requests?

My goal is to retrieve the HTML content of a JavaScript-generated website so that I can extract information using BeautifulSoup. However, when I attempt to request the HTML, the data I receive is from before the page fully loads. Below is the code snippet ...

Obtaining JSON data in a separate JavaScript file using PHP

I have an HTML file with the following content: // target.html <html xmlns="http://www.w3.org/1999/xhtml"> ... <script src="../../Common/js/jquery-ui-1.10.3.js"></script> <script src="../../Common/js/select.js" type="text/javascript"& ...

Why is my CSS and Bootstrap full-page image not displaying properly?

I've been struggling to get a full-page image to display on my website and resize responsively across different screens. I've searched through w3schools and Stack Overflow for solutions, but no matter what I try, it just doesn't seem to work ...

Conceal the Angular Material toolbar (top navigation bar) automatically when scrolling downwards

In my Angular application, the main navigation consists of a standard toolbar positioned at the top of the page. My goal is to have this navigation bar smoothly scroll up with the user as they scroll down, and then reappear when they scroll back up. I at ...

ASP.NET user control cannot locate hidden field

In an asp.net usercontrol (.ascx) that contains an HTML hidden field, there are some issues to address. <input id="HiddenField1" type="hidden" runat="server" /> When the user control triggers a HTML pop-up window, users input values which are then ...

JavaScript JQuery alert popup fails to display

I have been attempting to create an alert pop-up using JQuery that will display when a user clicks on submit without filling out the form. However, when I test my code by leaving the form empty and clicking 'submit', the page just refreshes with ...

jQuery live DataAttribute manipulation

Here is the code snippet I am working with: <head runat="server"> <title>Sidebar</title> <link href="css/style.css" rel="stylesheet" /> <script src="scripts/jquery-1.11.1.min.js"></script> <script src ...

Pair of input fields consolidated under a single label

Take a look at the scenario below: <label>Range from <input name='min_value'/> to <input name='max_value' /> </label> Is this structurally correct according to the W3C guidelines which specify that a l ...

Issue with jQuery form submission not retrieving input value

[Beginner inquiry] I am using contact form 7 on my WordPress website. I have two input fields where I need to display the event title and price: if (window.location.href.indexOf("event") > -1) { var title = $('.entry-title').text(); var ...

Excessive content in Bootstrap row extends outside browser window dimensions

I'm having an issue with the Bootsrtap row overflowing past the desired width, causing a scrollable area on the browser. Does anyone know how to fix this? You can see the site here: www.testing.cpukeychains.comhttps://i.sstatic.net/cDcot.png ...

Save a FlexTable as an HTML file using R script

Is there a way to export a FlexTable created using the ReporteRs package as an .html file in RStudio without losing the formatting? Currently, I can manually save the table as a webpage by clicking on 'Export' and choosing 'Save as webpage& ...

Unable to adjust price slider on mobile device, bars are not sliding

I have been utilizing the jQuery slider from lugolabs.com for my website, and while it works flawlessly on desktop, it seems to have issues when viewed on mobile devices. You can check out the slider at this link: The library used for this slider is jQue ...

Identify the custom HTML tag that is causing issues in IE8

Our angular.js app heavily utilizes custom tags, and I am faced with the challenge of ensuring compatibility with IE8. Here's what we have set up: Angular (1.1.5) HTML5 mode Custom tags for directives are used extensively (without replacing them) I ...

A guide on how to display an unfamiliar HTML tag on a QLabel

I am trying to display text in a QLabel that includes angular brackets <MyText>, but it does not show up. I want the text to be displayed with the angular brackets included. For instance: Input string: <b> <MyText> </b> Output ...

What are some methods for turning off auto-validation in Internet Explorer 10 when using HTML 5?

When I added the max-length attribute, I encountered an issue where I am receiving a certain message in IE (Internet Explorer). However, I do not want this message to appear as it is unnecessary - the validation should occur silently. I have tried using th ...

Effective ways to replace an image using JavaScript

I am currently working on implementing a show/hide function, but I am encountering an issue with swapping the image (bootstrap class). The show-hide function is functioning properly; however, I am struggling to determine which class is currently displayed. ...

Adding an attribute to the last item of an Angular / NGX Bootstrap component

I am working with a dynamic list that utilizes NGX Bootstrap Dropdowns to showcase 4 sets of dropdown lists. However, the Dropdowns in the final list are getting obscured off-page. Thankfully, NGX Bootstrap offers a solution in the form of a dropUp option ...

Using the v-for loop to generate radio inputs results in selecting multiple radio buttons with identical values

Having a bit of trouble explaining, I've developed a basic rating system that utilizes input type ="radio" for an array of products. By using v-for="product in products", I iterate through the array and display all the products on the webpage. ...

Chrome's navigation zoom feature enhances the user experience by allowing for easy

My website has a responsive layout that functions perfectly on mobile Safari (iOS), but I've encountered an unusual issue when using Chrome on Android. Whenever I click on a link in the vertical navigation that is not at the end, Chrome opens a sort o ...

Having trouble finding a solution to prevent code from automatically adding a class in jQuery/JavaScript?

I am currently in the process of customizing the FlexNav Plugin. I have made a modification to allow sub-menus to open on click instead of hover. However, a new issue has arisen where it requires two clicks to open a submenu. Upon investigation, I have i ...