Personalizing the Navigation Bar

I am in the process of designing the navigation bar for my website that will work seamlessly on both desktop and mobile devices.

To view my progress so far, check out this JS Fiddle link

Here is the HTML code I have created:

<div class="container-fluid">
  <nav class="navbar navbar-expand-sm navbar-light">
    <a class="navbar-brand" href="#">Navbar</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" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <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="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Dropdown
          </a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Disabled</a>
        </li>
      </ul>



      <div class="row no-gutters ml-auto">

        <div class="col-3">
          <button class="btn btn-outline-warning btn-sm mr-1" data-toggle='modal' data-target='#login'>
                        <i class="fas fa-sign-in-alt mr5"></i>
                        Login
                    </button>
        </div>
        <div class="col-6 ml-auto">
          <form class="form-inline mr-1" action='/search' method='POST'>
                        <div class="input-group input-group-sm mx-auto">
                          <input type="text" class="form-control" name='search_string' placeholder="Search" value=''>
                          <div class="input-group-append">
                            <button class="btn btn-outline-warning" type="submit"><i class="fas fa-search mr5"></i></button>
                          </div>
                        </div>
                    </form>
        </div>
        <div class="col-3 text-right">
          <div class="dropdown">
              <button class="btn btn-outline-warning btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown
              </button>
              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
                <a class="dropdown-item" href="#">Dropdown Option</a>
                <a class="dropdown-item" href="#">Dropdown Option</a>
                <a class="dropdown-item" href="#">Dropdown Option</a>
                <a class="dropdown-item" href="#">Dropdown Option</a>
                <a class="dropdown-item" href="#">Dropdown Option</a>
                <a class="dropdown-item" href="#">Dropdown Option</a>
                <a class="dropdown-item" href="#">Dropdown Option</a>
              </div>
            </div>
        </div>


      </div>



    </div>
  </nav>
</div>

I am encountering an issue where the right-aligned menu items within the row are being spaced apart due to the `col` class. I want them to be displayed next to each other with a `mr-1` spacing when in desktop mode, but nicely spaced out in columns when switching to mobile mode. Despite trying different flex-row configurations, I have not been successful in achieving the desired layout. Being new to Bootstrap 4, I would appreciate any guidance on the best approach to resolve this challenge.

Ultimately, I envision my menus looking similar to the following images for LG and XS screen sizes respectively: [LG Image](https://i.sstatic.net/MG56B.png) and [XS Screen Image](https://i.sstatic.net/eAEoH.png). I am having trouble aligning `Menu 1` completely to the right-hand side to match up with the `Dropdown` option.

In comparison to Bootstrap 3, I find Bootstrap 4 more challenging to master. If achieving the desired layout is possible using only rows and cols without depending on the navbar structure, I would welcome any suggestions or insights.

Answer №1

If you're looking to rearrange elements in your Bootstrap layout, one option is to use the push/pull classes. Here's an example that demonstrates how to achieve this: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_grid_ex9&stacked=h

<div class="row row-fluid">
<div class="col-md-2">
Your burger-menu here
</div>
<div class="col-md-2 offset-md-8">
Your burger-menu here
</div>
</div>

After setting up your top row using offsets or other methods, create a new row within the same container for the login, search, and dropdown functionalities.

<div class="row row-fluid">
<div class="col-md-2">
login code
</div>
<div class="col-md-8">
search code
</div>
<div class="col-md-2">
dropdown code
</div>
</div>

Remember to adjust column sizes for different screen sizes and try push/pull techniques if needed to fine-tune the placement of your divs within the layout.

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

Click event in jQuery triggers element movement

I'm having a tough time figuring this out. I initially thought it was the negative margin causing the issue, but even after removing it, the problem persists. Check out the link below to see what I mean when you click on one of the list items at the ...

What is the best way to center text vertically in a <div> using CSS?

This is my first attempt at creating a chrome extension, and I am currently working on centering text. Right now, I am using text-align: centre; to align the text horizontally, but I am struggling to figure out how to align it vertically. As a result, my t ...

What is the strategy to load a div exclusively when triggered by a click event, instead of loading it

Can anyone assist me with a problem I am facing on my scripting page? I am currently working on a website that showcases properties. I would like to know how to prevent a specific div from loading when the page initially loads, and instead have its content ...

Position two div elements evenly with text enclosed in a container

I'm looking to incorporate two distinct blocks of text into a container https://i.stack.imgur.com/6mFZK.png Criteria: Text 1: positioned at the top left corner (85% of box size) Text 2: positioned at the bottom right corner (15% of box size) I&ap ...

A website with two distinct pages, where only the first page is refreshed

I have split the content of my HTML page into 2 separate subpages, based on the references provided below: Multiple distinct pages in one HTML file This is how my code is structured: ... <script> function show(shown, hidden) { document.getEle ...

Having trouble determining the dimensions of a newly added element

I am using jQuery to dynamically add an image but I am unable to retrieve its dimensions (width and height). Below is the snippet of code from my HTML file: <input type="checkbox" id="RocketElement" data-id="1"> And here is the JavaScript/jQuery c ...

Having trouble vertically aligning text in Bootstrap 4?

I'm having trouble getting the text to align vertically in the middle and closer to the image. The vertical-align:middle property doesn't seem to be working for me. Additionally, when I resize the screen width, the layout changes from a horizonta ...

Collapse the columns and set them to float on the left side

My current setup might not be the most visually appealing, but it gets the job done. I have several col-md-4 tags in place. The issue arises when the height of the first tag is larger than the ones next to it, causing the subsequent tag to appear in the mi ...

Using JavaScript to create a search bar: Can "no results found" only show after the user has completed typing their search query?

How can I ensure that the "no match" message only appears after the user has finished typing in their search query, rather than seeing it while they are still typing "De" and the list displays "Demi"? usernameInput.addEventListener("keyup",function(){ ...

What is the best way to ensure the menu background aligns perfectly with the header in HTML/CSS?

Issue: Menu background doesn't align with header. (visible in the image provided below) VIEW IMAGE Any suggestions on how to resolve this alignment problem? CSS CODE : .header { margin:0px auto; max-width: 960px; } #header { height:30 ...

How can I execute a function when ng-click is triggered on an <a> tag, and ensure it opens in a new tab?

I am facing an issue with an element in my code, which is as follows: <a ng-click="vm.openPage(page)">{{page.pageId}}</a> Within the vm.openPage() function, there are validations that need to be performed before redirecting to the page refere ...

The select tag in an iOS app is functional, but unfortunately the multiple select feature is not functioning correctly

When developing my ios app, I utilize loadHTMLString to display a view. Within this view, I generate a select tag with multiple selection options using the following HTML code: [HTML appendFormat:@"<select multiple=\"multiple\" onchange=&bsol ...

Employ CSS flexbox and/or JavaScript for creating a customizable webpage

I am in the process of developing a basic IDE for an educational programming language that has similarities to Karel the Dog. One major issue I am encountering is creating the foundation HTML page. The IDE consists of 4 main areas: Toolbox (contains but ...

Having trouble setting the selected option in Jquery by value?

I have exhausted all options found on the internet. What could I be overlooking? The desired option is not getting selected. Here is the troublesome section of code. I have also included some other attempts that I have commented out. If it helps, this li ...

Modifying the background color of a specific section on a Bootstrap website

If you visit a bootstrap website like www.teachyourselfpython.com, you will notice that the welcome and resources sections have a white background color. I've been trying to figure out how to change this white background to a light grey specifically f ...

Leveraging HTML5's local storage functionality to save and manage a collection of list elements within `<ul>`

I need help with saving a to-do list in HTML so that it persists even after refreshing the browser. Can anyone assist me? html <!DOCTYPE html> <html> <head> <title>My To-Do List</title> <link rel="sty ...

Using JavaScript Object Constructor to alter text color

Seeking some guidance as a newbie here on how to deal with a problem I'm currently tackling. I understand that using an object constructor may not be the most efficient way to handle this, but I'm eager to enhance my knowledge of objects. My quer ...

Transmit JSON Data via POST Method and Retrieve Using Node.js (Without the Use of Body Parser)

Can anyone help me with sending JSON data from HTML and receiving it in Node.js? I've been trying for hours and I'm getting frustrated. It seems like I'm close to a solution but no luck so far. In my VSCODE, the response is null (req.body = ...

Triggering the 'Next' function with a key press event

Currently, I am utilizing the following code to manage the keydown event for the tab and enter keys within an input field. $(document).on('keydown', ".className" , function(e) { var keyCode = e.keyCode || e.which; alert(keyCode) / ...

Browser unresponsiveness triggered by excessive Ajax setInterval functionality

Here is the test code I am currently using: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ajax - one variable test</title> <style> body{ font-size: 12px; font-family: Arial;} </styl ...