What are some tips for customizing the NavBar Bootstrap 4 Layout to fit a unique design?

Good evening everyone,

I am currently working on a website project for a client who has provided me with specific requirements for the Navbar design. While it seemed straightforward at first, I have spent several hours trying to perfect the layout. I am using Visual Studio 2019 Community for development, Razor for web pages, and Bootstrap 4 for the base CSS. The design is focused on mobile-first approach and the layout is mostly correct, but I need some assistance. I have two questions in total, and I can create another thread for the second question if needed.

My issue lies with a basic out-of-the-box Bootstrap NavBar where one of the elements is causing a problem.

<nav class="navbar navbar-expand-sm navbar-dark">
    <a class="navbar-brand" href="/"><img src="~/Images/Logo.png" /></a>

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse p-3" id="navbarSupportedContent">
        <div class="row">
            <div class="col-6 border-right">
                <ul class="navbar-nav">
                    <li class="nav-item active">
                        <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">News</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">About Us</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Car Sales</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact Us</a>
                    </li>
                </ul>
            </div>
            <div class="col-6">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="#">MOT</a>
                    </li>
                    <li class="nav-item pb-3">
                        <a class="nav-link" href="#">Services</a>
                    </li>
                    <partial name="_LoginPartial" />
                </ul>
            </div>
        </div>
    </div>

    <div class="mx-auto">
        <a class="nav-link" href="#">Book an Appointment</a>
    </div>
</nav>

I have made some custom CSS modifications to override Bootstrap styles.

nav {
    padding-bottom: 15px!important;
}
.navbar {
    ...
}

.navbar-brand img {
    max-height: 105px;
}

The desired mobile layout can be viewed here. However, when the screen size exceeds 456px, the "Book an Appointment" link shifts to the right of the hamburger button. My question is, how can I keep it aligned under the Logo and hamburger button until reaching 576px where the layout changes?

If the device transitions to tablet or desktop view, the Navbar should adapt accordingly. While I have a solution in mind, I am open to suggestions for a more efficient approach. The desktop layout can be seen here, along with the corresponding code.

<nav class="navbar navbar-expand-sm navbar-dark">
    ...

My second question is regarding the best method to make the Navbar responsive and display two distinct layouts based on the device screen size. I plan to hide the desktop code on mobile using .d-sm-none .d-md-block classes and reveal it for desktop users. Any suggestions or questions are welcome!

EDIT: Complete Nav Code with Update from Nisharg

<nav class="navbar navbar-expand-sm navbar-dark">
    ...

Answer №1

Top Solution

I made a modification by replacing the final book appointment text with the logo.

As a result, in all screen resolutions, your book appointment text now appears below the logo.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<nav class="navbar navbar-expand-sm navbar-dark">
    <div class="image_wrapepr">
        <a class="navbar-brand" href="/"><img class="w-100" src="PDFs/img/lol1.jpg" /></a>
        <a class="nav-link" href="#">Book an Appointment</a>
    </div>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
        aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse p-3" id="navbarSupportedContent">
        <div class="row">
            <div class="col-6 border-right">
                <ul class="navbar-nav">
                    <li class="nav-item active">
                        <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">News</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">About Us</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Car Sales</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact Us</a>
                    </li>
                </ul>
            </div>
            <div class="col-6">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="#">MOT</a>
                    </li>
                    <li class="nav-item pb-3">
                        <a class="nav-link" href="#">Services</a>
                    </li>
                    <partial name="_LoginPartial" />
                </ul>
            </div>
        </div>
    </div>
</nav>

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04746b747461762a6e7744352a35322a34">[email protected]</a>/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></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

JavaScript plugin designed for effortless conversion of JSON data to structured HTML code

I want to add this JSON data to an HTML element. [ { "website":"google", "link":"http://google.com" }, { "website":"facebook", "link":"http://fb.com" } ] Is there an easy way to convert this using a plugin ...

Unable to locate image files stored in vendor/images in the Rails 4 view

I have successfully set up a custom bootstrap theme with Rails 4, and placed the image file here: /vendor/assets/images/custom_bootstrap_theme/demo/bg01.jpg The index.html.erb file is referencing this image as follows: <img src="/vendor/assets/image ...

Why doesn't the WordPress Genesis child-theme inherit the parent CSS styles?

I am new to using the Genesis framework and I find myself confused about its child themes. The Genesis theme comes with its own stylesheet, but in order to use Genesis, you need to install a child theme. However, the child themes I have come across (such ...

Looking for guidance on managing view redirection in Django (Updated)

I ran into an issue with a previous question I posted, you can find it here Due to some formatting errors because it was my first time posting a question, the original question is currently closed. I have made edits and resubmitted it for reopening, but I ...

Managing various choices in a Select menu using a single submit button

My method of using mysql to insert data into dropdown menus is not working as expected. Each dropdown menu has a unique name assigned from the database query $stmt. The content for each dropdown menu is retrieved through another query, $stmt2. My goal i ...

Guide to correctly selecting <i> tags within a <p> tag using jQuery

I'm attempting to retrieve the text from the i (italic) elements within a paragraph using this code: $('p').each(function(j, element){ if($(element).is("i")){ console.log("The value is: "+$(element).text()); } }); However, ...

Disable the ability to scroll the background when the lightbox is opened

Currently incorporating Featherlight for a lightbox feature. Encountering an issue where the background remains scrollable when the lightbox is open. Typically, lightboxes require adding a class to the body with overflow:hidden; to resolve this problem. S ...

It appears that Internet Explorer is still animating/processing my loading.gif despite being set to display:none

It seems that the issue I'm encountering is related to the inconsistent starting position of the loading.gif animation when performing an ajax request. In Internet Explorer, the animation appears to start from a random point, while in Firefox it alway ...

Transferring JSON data from Django for visualization on a D3 graph

I'm currently working on customizing a D3 bar graph found at http://bl.ocks.org/3885304 to accommodate JSON data from Django. In Django, I have a variable that holds JSON formatted data like this: [{"score": 1, "color": "blue"}, {"score": 5, "color": ...

Why do certain full screen websites not align with my screen width properly?

When I use my 1920px wide screen and inspect the HTML tag with Chrome DevTools on websites like Firebase or Facebook Messenger, I notice a difference: https://i.sstatic.net/1nknq.png Despite my screen width being 1920px, these websites appear fullscreen ...

Exploring the functionality of the onblur HTML attribute in conjunction with JavaScript's ability to trigger a

How do the HTML attribute onblur and jQuery event .trigger("blur") interact? Will both events be executed, with JavaScript this.trigger("blur") triggering first before the HTML attribute onblur, or will only one event fire? I am using ...

Creating specific CSS classes for individual slides in a basic slider framework

So, I have a rather simple slider that is created using only CSS. Each slide has unique labels for navigation buttons. The main question here is: how can I dynamically add or remove classes to specific items on the slide only when that particular slide is ...

Iterate through the contents of a directory and display the HTML content corresponding to each file

Currently, I am diving into the world of PHP Laravel. The project I am working on involves repeating blocks of HTML code in my template, which I want to streamline using a loop. My idea is to automate this process by implementing a foreach loop in my Vue ...

What is the best method for removing table rows with a specific class?

I have an html table with several rows, and for some of these rows the class someClass is applied. My question is: How can I delete the rows that have a specific class? <table> <tr class="someClass"> ...</tr> <tr class="someClass"> ...

Tips on utilizing the identical template in ngIf

I need to display different templates based on certain conditions. For example: <template [ngIf]="item.url.indexOf('http') == -1"> <a class="ripple-effect" [routerLink]="[item.url]" *ngIf="isUserLoggedIn == true" > ...

How to implement an 8-column layout within a 12-grid bootstrap framework?

Hey guys, so I've been trying to recreate this page with Bootstrap and it's all going smoothly except for this one part. Here is the link I'm referring to: https://i.sstatic.net/0mXMm.png I have 2 questions: Which HTML element should I us ...

Combining SVG icons into a sprite sheet and referencing them using the elements <defs>, <g>, and <use> to optimize

I am attempting to incorporate an SVG icon within my HTML code for future use, but I'm facing issues with its display on the webpage when referenced using the <use> tag. Initially, I copied the SVG code of the icon and inserted it directly into ...

Hide the scrollbars on the sidebar

I'm attempting to recreate a sleek scrollbar that caught my eye on the website . To achieve this, I need to have a screen larger than 955px in order to display the sidebar. However, when my sidebar overflows in the y direction, it causes an additional ...

Fluctuate the window.location with jQuery or javascript

My goal is to create a functionality where clicking an image will toggle the window.location url between '#' and '#footer'. The current code I have for this is: <script> function clickarrow(){ var rd=Math.floor(Math.random() ...

Could the conflicting interaction between CSS transformation and animation be resolved by adjusting the order of the HTML elements

Hey there! I'm facing an interesting challenge with my menu design. The menu has rounded ends and diagonal spaces created using CSS transform skewx. Additionally, I have an animated element on the page. The issue arises when the animated element is p ...