'How to reduce border-bottom width form one side in html?

Actually I have to show bottom bar to currently active page. I am using ternary operator in PHP . The bottom bar is showing up but its horizontal width is a bit extra . I'm not been able to reduce its width . Here's a picture of it:

https://i.stack.imgur.com/9mWRJ.png

Here's ternary operator I used:

 <ul class="navbar-nav me-auto mb-2 ms-auto mb-lg-0">
                    <li class="{{'/' == request()->path() ? 'nav-item' : ''}}">
                        <a class="nav-link" href="{{route('home')}}">Home</a>
                    </li>
                    <li class="{{'novels' == request()->path() ? 'nav-item' : ''}}">
                        <a class="nav-link" href="{{route('novels')}}">Novels</a>
                    </li>
                    <li class="{{'about' == request()->path() ? 'nav-item' : ''}}">
                        <a class="nav-link" href="{{route('about-us')}}">About Us</a>
                    </li>
                    <li class="{{'contact' == request()->path() ? 'nav-item' : ''}}">
                        <a class="nav-link" href="{{route('contact-us')}}">Contact Us</a>
                    </li>
                </ul>

Here's the css:

 .nav-item {
    border-bottom:3px rgb(0, 0, 0) solid;
   margin-bottom: 19px;
   }


Solution 1:[1]

First of all, the problem is not in the PHP (rather Smarty or Blade template engine) logic. The problem is in your CSS definition. You set border of your <li> items.

Proposed solution

Please use the css class nav-item for all your <li> in your navbar section. Because all of these <li> elements in your navbar describe an navigation item independent on the fact that, whether the current page equals one of them or not.

Use rather an additional class like current for marking the navigation item of actual page. I did it for you.

<ul class="navbar-nav me-auto mb-2 ms-auto mb-lg-0">
    <li class="nav-item {{'/' == request()->path() ? 'current' : ''}}">
        <a class="nav-link" href="{{route('home')}}">Home</a>
    </li>
    <li class="nav-item {{'novels' == request()->path() ? 'current' : ''}}">
        <a class="nav-link" href="{{route('novels')}}">Novels</a>
    </li>
    <li class="nav-item {{'about' == request()->path() ? 'current' : ''}}">
        <a class="nav-link" href="{{route('about-us')}}">About Us</a>
    </li>
    <li class="nav-item {{'contact' == request()->path() ? 'current' : ''}}">
        <a class="nav-link" href="{{route('contact-us')}}">Contact Us</a>
    </li>
</ul>

Then you should use the following CSS definition:

.nav-item.current a.nav-link{
    border-bottom:3px black solid;
    padding-bottom: 10px;
}

Please upvote and accept this answer, if it solves your problem.

Here is a screenshot of my solution:

enter image description here

Solution 2:[2]

I'm not able to read or test your code. We may require the code where you declared the space between your nav-item (li); however, if the space between is caused by padding-right, then change it to margin-right, or get that look from flex gap; it should work.

//no changes needed in this code
 .nav-item {
    border-bottom:3px rgb(0, 0, 0) solid;
   margin-bottom: 19px;
   }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Selim Acar
Solution 2