"Incorporate a bottom border into the hover, focus, and active states of the Bootstrap Wordpress navigation menu

I'm looking to enhance my menu navigation buttons by adding a 3px tall border at the bottom when they are hovered over, selected, or are the current menu item. I don't want a simple text underline effect, but rather a distinct border that matches the width of the navigation button above it. I've been searching for an example to follow with no luck - any assistance would be greatly appreciated.

Currently, I am working with a WordPress dynamic menu:

<div class="collapse navbar-collapse navbar-ex1-collapse">
   <ul id="menu-main-menu" class="nav navbar-nav">
     <li id="menu-item-32" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-6 current_page_item menu-item-32 active">
     <li id="menu-item-31" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-31">
     <li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30">
     <li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29">
     <li id="menu-item-26" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-26 dropdown">
     <li id="menu-item-25" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-25">
     <li id="menu-item-498" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-498">
     <li id="menu-item-499" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-499">
</ul>
</div>

Answer №1

Adjusting Border Width to Match Text Above

To make the width of the border equal to the width of the text above it, you can wrap the text of each link into <span></span> and utilize the box-shadow property on this span.

Implementation on Your Website

Update: The code for the dropdown menu has been added.

I have created a Minimal, Complete, and Verifiable example based on your site. To resolve your issue, wrap the text of each link into <span></span> and apply the following CSS:

.dropdown-toggle {
  margin-top: 0;
}
#menu-main-menu .current-menu-item a,
.nav > li > a:focus,
.nav > li > a:hover {
  box-shadow: none;
}
@media (min-width: 768px) {
  .navbar-nav > li > a {
    padding: 0 10px;
  }
  .navbar-nav > li > a > .fa-fw {
    width: auto;
  }
  .navbar-nav > li > a > .fa-fw,
  .navbar-nav > li > a > span {
    display: inline-block;
    padding: 15px 0;
  }
  .navbar-nav > li > a:hover > span,
  .navbar-nav > li > a:focus > span,
  .navbar-nav > .active > a  > span {
    box-shadow: inset 0px -3px 0px #f2ab00;
  }
}

Check the result here: https://jsfiddle.net/glebkema/jacL6zme/

/******** MINIMAL, COMPLETE AND VERIFIABLE EXAMPLE ********/
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css');
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css');
@import url('https://fonts.googleapis.com/css?family=Poppins:300,500,600,700');

body {
  background-color: #3b3e4d;
  color: #fff;
  font-family: "Poppins",sans-serif;
  font-size: 16px;
}

/* fragment of your bootstrap.min.css */
a {
  background-color:transparent !important;
}
#menu-main-menu .current-menu-item a {
  color: #f2ab00;
  box-shadow: inset 0px -3px 0px #f2ab00;
  display: inline-block;
}
.navbar-fixed-top {
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 10px;
}
.navbar-nav>li>a {
  line-height: 20px;
}
.nav>li>a {
  position: relative;
  display: block;
  padding: 10px 15px;
  color: #fff;
}
.nav>li>a:focus, .nav>li>a:hover {
  text-decoration: none;
  color: #f2ab00;
  box-shadow: inset 0px -3px 0px #f2ab00;
  display: inline-block;
}

/* More styles... */

},
});

Enhancing Bootstrap Navbar Design

To style your Bootstrap navbar with consistent border widths matching text, I've utilized the span:first-child selector to account for links containing

<span class="sr-only"></span>
.

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

body {
  background: #9d9d9d;
}
.navbar-nav > li > a {
  color: #fff !important;
  font-transform: uppercase;
  font-weight: bold;
}
.navbar-nav > li > a:hover > span:first-child,
.navbar-nav > li > a:focus > span:first-child,
.navbar-nav > .active > a  > span:first-child {
  color: #f2ab00 !important;
}

/* Additional styling... */

}
<nav class="navbar navbar-inverse">
  <div class="container-fluid">

    <ul class="nav navbar-nav">
        <li class="active"><a href="#"><span>Link</span><span class="sr-only">(current)</span></a></li>
      <li><a href="#"><span>Link</span></a></li>
    </ul>

    // More navigation elements...

  </div>
</nav>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

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

Designing checkboxes with accompanying labels

I am looking to create a vertical list of checkboxes with labels, following the layout below: My options [x] Checkbox 1 [ ] Checkbox 2 [ ] Checkbox 3 [ ] Checkbox 4 I have implemented the method suggested in this Stac ...

Discover the secret to aligning HTML radio buttons vertically using only CSS in this snippet

I stumbled upon this amazing CSS-only slideshow with thumbnails for my project here. I've been experimenting with the code to try and align the thumbnails vertically on the right instead of horizontally at the bottom, but haven't had much luck... ...

Rails encounters problems when assets are modified

I recently inherited a small Rails website. When I attempted to make a change to a css file, I encountered an error page (code 500) in Rails with the following message: No such file or directory - /.../cache/assets/sprockets%2F1450c8f5d2b6e201d72fa175586b ...

When starting to build a website, should the Master Page be the first element to code, or perhaps the header and menu?

I have been tasked with building a website using ASP.net and I already have the design in mind. This will be a standard website project for me, but it's also my first time working on something like this. I'm feeling a bit lost on where to begin. ...

Is there a way to adjust the dimensions of Google charts within a Bootstrap tab for a more customized appearance?

I've been working on a page that features tab navigation using Twitter Bootstrap and I want to include Google charts within each tab's content. However, I've encountered an issue where the charts are appearing in different sizes despite spec ...

Determining the total of input values based on identification number

Can anyone help me figure out how to calculate the total sum of the values entered using IDs? I've been struggling with it and can't seem to get it to work. Your assistance would be greatly appreciated. <input type="number" id=&quo ...

jQuery neglecting events of child elements

I am facing an issue with the following list structure: <ul id="menu"> <li style="background-image:url('Images/X-AFH-Company-Office-Background.png')" id="office"> <div >Company / Office</div> ...

Populate the line path of amCharts and eliminate the y-axis labels

I'm experimenting with amCharts to generate the following: https://i.sstatic.net/LWAQr.png Currently, I'm facing some challenges: The y-axis labels are not disappearing. I attempted to use theYAxis.disabled = true; as mentioned in the documen ...

How to implement CSS styling for a disabled component

In my application, I have a FormControlLabel and Switch component. When the Switch is disabled, the label in FormControlLabel and the button in Switch turn gray. However, I want to maintain the color of both the label (black) and the button (red). To test ...

Swapping out LinkButtons using jQuery

[EXPLANATION] (apologies for the length) In my gridview, users have the option to add a new entry or edit an existing one. When they click on either 'Add' or 'Edit', a popup window appears for them to input the information for the new ...

isolating child pointer events in CSS styling

I am looking for a way to prevent the click event on the checkbox from triggering the parent click event that opens a modal. Check out this gif demonstrating the issue: https://gyazo.com/856a84242349609f4506095de33ee1df Let me explain further what's ...

Enhancing Your Website with Multiple Background Images in CSS3

Having trouble understanding how to position multiple background images with CSS3. I'm struggling to get them to display at the top, middle, and bottom of the page. Can you help me figure out how to make an image appear at different positions using a ...

There are certain CSS3 properties that are not being accounted for in the CSS min

I've incorporated several newer CSS3 properties in my stylesheet, but I'm concerned that the minification tool I'm currently utilizing may not be capturing all of these properties: .big-blue-button:hover { text-decoration: none; bac ...

Best practices for personalizing components installed with Bower

After using Bower to install a package such as bootstrap-sass-official, it is stored in the bower_components directory. Packages like Bootstrap allow for customization by making changes to the file bower_components/assets/stylesheets/_bootstrap.scss. You c ...

Position the div element below the navigation bar

I am attempting to embed a Leaflet map within a standard Sails.js view. Sails.js automatically includes a page header on every page. Currently, with a fixed height, the map appears like this: #mapid { height: 400px; } https://i.sstatic.net/pzOdql.jpg ...

CSS - text featuring a gentle shadow hue and a deeper foreground color

I'm encountering an aesthetic issue where my list of texts have random light/bright colors, making them hard to read on white backgrounds. I've tried setting the text color to shadow, but now I want the text itself to be a darker, more readable c ...

What steps should I take to establish an efficient folder organization system for a website utilizing HTML, CSS, and Javascript with Twitter Bootstrap?

After cloning the latest release of Twitter Bootstrap using Git with the command 'git clone git://github.com/twbs/bootstrap.git', I am in the process of creating an HTML/CSS site utilizing Bootstrap. Upon reviewing this answer on Stack Overflow ( ...

What is preventing these arrows from spinning?

I am struggling to find a solution to rotate the arrows on the x-axis, which are added by the::before pseudo-element when the link is active. Despite trying keyframes and searching online, I have not been able to achieve the desired result. Below you wil ...

What is the best way to ensure the meta value is updated to reflect exactly what is displayed on the

I attempted to change a meta value on the WordPress frontend using the code below: function code_form() { $content = ''; $content .= '<h2> code </h2>'; $content .='<form method="post">'; $content .= ...

Conditional CSS comments for browsers and Internet Explorer version 9

Something peculiar is happening to me. I'm currently using Internet Explorer 9 and experimenting with changing the browser mode to IE 7 or IE 8, among others ... The issue arises when I include this code: <!--[if lt IE 7]> <link type=&bsol ...