I would like to add a border bottom to my menu navigation button that is hovered over, or selected, or the current menu item. I dont’ just want to add a “text-decoration:underline”, I would like to have a 3px tall border and only have it the width of the nav item above it, I can’t find an example that applies – any help is greatly appreciated:
I am using 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>
How 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 apply thebox-shadow
property to thisspan
.On your website
UPD. I’ve added the code for the dropdown menu.
I’ve made a Minimal, Complete, and Verifiable example based on your site. You have to wrap the text of each link into
<span></span>
and add this CSS to solve your issue:Please check the result: https://jsfiddle.net/glebkema/jacL6zme/
For Bootstrap navbar
I’ve used the
span:first-child
selector because some links may contain<span class="sr-only"></span>
.