Guide to positioning a bootstrap navbar toggle button to the left or right of the logo

My React app includes a bootstrap navbar with the following code -

 <nav className="navbar navbar-default navbar-expand-sm navbar-light bg-light">
      <div className="container-fluid">
        <div className="navbar-header">
          <button
            className="navbar-toggler"
            type="button"
            data-toggle="collapse"
            data-target="#navbarTogglerDemo03"
            aria-controls="navbarTogglerDemo03"
            aria-expanded="false"
            aria-label="Toggle navigation"
          >
            <span className="navbar-toggler-icon"></span>
          </button>
          <NavLink className="navbar-brand mx-auto" to="/">
            <h4>Crafting Social Minds</h4>
          </NavLink>
        </div>
        <div
          className="collapse navbar-collapse me-auto"
          id="navbarTogglerDemo03"
        >
          <ul className="navbar-nav ms-auto navbar-custom">
            <li className="nav-item">
              <NavLink
                className="nav-link"
                exact
            
                to="/"
              >
                Organised Events
              </NavLink>
            </li>
            <li className="nav-item">
              <NavLink
                className="nav-link"
                to="/upcoming-events"
              >
                Upcoming Events
              </NavLink>
            </li>
            <li className="nav-item">
              <NavLink
                className="nav-link"
             
                to="/new-event"
              >
                New Event
              </NavLink>
            </li>
            <li className="nav-item">
              <NavLink
                className="nav-link"
               
                to="/about"
              >
                About Us
              </NavLink>
            </li>
          </ul>
          {/* <div className="social-part">
            <i className="fa fa-facebook" aria-hidden="true"></i>
            <i className="fa fa-twitter" aria-hidden="true"></i>
            <i className="fa fa-instagram" aria-hidden="true"></i>
          </div> */}
        </div>
      </div>
    </nav>

On larger and medium devices, the navbar appears as intended. However, on smaller devices, the toggle-navbar button appears above the brand name instead of alongside it. I am looking for a solution to this issue without altering the layout for larger devices using only bootstrap classes. Is there a way to achieve this?

For large and medium devices, the navbar looks like this -

https://i.sstatic.net/qy3ne.png

On small devices, the navbar is displayed as follows -

https://i.sstatic.net/Jxu7S.png

Answer №1

Your usage of me-auto and ms-auto for margin end and margin start is intended for Bootstrap 5, not Bootstrap 4 as indicated by the tag on your post. In Bootstrap 4, mr-auto and ml-auto should be used instead.

If you desire to have the button aligned on the left and your brand name on the right, consider overriding the default margin with mr-0 mr-md-3. Keep in mind that with the current h4 styling on your brand name, it may only fit effectively on a display with a width of 320px.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="583a37372c2b2c2a3928186c766e7668">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81e3eeeef5f2f5f3e0f1c1b5afb7afb1">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>

<nav class="navbar navbar-expand-md navbar-light bg-light">
    <div class="container-fluid">
        
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <a class="navbar-brand mr-0 mr-md-3" href="#">
            <h4>Crafting Social Minds</h4>
        </a>
        <div class="collapse navbar-collapse mr-auto" id="navbarTogglerDemo03">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="#">Organised Events <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Upcoming Events</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">New Event</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">About Us</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

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

"Enhance Your Website with Foundation 6.2's Spacious Gutter

The Foundation 6.2 documentation indicates that the default grid gutter size is 20px for small screens and 30px for medium screens. However, it fails to specify the default gutter size for large screens. Can you please provide information on the default ...

`Error occurring with React-router when refreshing nested pages causing CSS not to load`

Setting up a react-router for my first React webapp has been a bit tricky. It seems to be functioning properly except for the issue with CSS not loading on nested pages when they are refreshed. The CSS works fine for single level paths like /dashboard, bu ...

Guide on utilizing font-awesome icons stored in node-modules

After successfully installing font-awesome 4.0.3 icons through the npm install command, How can I incorporate them into an HTML file from the node-modules directory? If edits need to be made to the less file, do they have to be done within the node-modul ...

What is the best way to create a text shadow effect for a heading element?

Is it possible to create a centered heading like the one in this image using only CSS, without using flexbox? [EDIT] Below is an example using flexbox. However, there are some limitations with this code as it doesn't allow reusing the same class for ...

html/css: managing content overflow in web pages

While studying CSS, I created a sample page and encountered an issue where two of my divs were overflowing the content of the body, with the footer appearing above those divs. body { background-color: white; } #div1 { margin: 50px; text-align: jus ...

Resolving CSS Fluid Image Problem

Even though my site background is responsive and functions well, I am encountering problems with the images. I want them to appear "fixed" in the same position as the background, regardless of resolution changes. For example, resizing the browser from 990p ...

Separate the center icon from its corresponding text

Looking for a solution to center Font Awesome icons vertically while keeping the text aligned separately? Currently, the icons and text are centered together on the page, but I want the icons to be centered vertically and the text to follow independently ...

Linking multiple font files of the identical typeface to their respective CSS styles

I recently purchased the Didot font from myfonts.com, which includes different styles such as regular, bold, italics, and bold italics (each in separate files). While using WordPress, I noticed that when my users write articles with bold and italic text, ...

Use jQuery to place tags around the content of existing <li> elements

Using jquery, I have been able to successfully create a list by using the following code: $(list).append(item); (where list is the list reference and item consists of the $('<li>') elements being added). var item = $('<li>' ...

Center align a row with the help of Bootstrap 4.0

Here is some code with Bootstrap 4 classes that I am working with: <div class="container"> <div class="row"> <div class="col-xl-4 col-md-6 col-lg-4"> <div class="footer_widget"> <h3 class ...

What are some techniques for styling a label element with an empty for attribute using CSS?

Here is what I currently have: <label class="filter-label" for="pv[]181"> ::before white <span class="count">5</span> ::after </label> My goal is to modify the ::after element within that label, but so far my attempts ...

Icon overflowing due to Bootstrap 4 card title

I'm currently working on implementing an expand/collapse feature with a red close 'X' button in a Bootstrap 4 card. I've almost got it working, but when I try to place the red close icon outside the element that controls the expand/coll ...

Floating dropdown within a scrolling box

How can I ensure that the absolute positioned dropdown remains on top of the scrollable container and moves along with its relative parent when scrolling? Currently, the dropdown is displayed within the scrollable area. The desired layout is illustrated i ...

Flexbox helps create responsive layouts with ease

Utilizing flex to centrally position my element within my layers has worked well for me, but I encountered an issue when switching to a smaller screen size. The element simply scales down in size instead of taking up the full width like it does with Bootst ...

Margin of Contents in a Table

I have created a table within a box on my webpage. The default setting centers the table inside the box, but I want it to align with the bottom border of the box instead. Each row in the table contains two cells, each cell displaying a picture that I would ...

Differences in the way CSS handles 'root' within an external .css file

As I delve into the world of CSS, I've encountered a puzzling issue that has me scratching my head. My objective is to change the background color of the viewport to red. When I tried using the following code in an external .css file and linked it to ...

Building an Online Presentation through Imagery

While I am aware that there are numerous ways to implement a slideshow on a website, my question is centered around identifying the most widely used approach. Specifically, I am interested in knowing which method is considered the most mainstream for crea ...

I'm curious, do you know the standard width of an HTML table cell <td>?

Can someone point me in the right direction to find the default width of a <td>? I've been searching through the HTML Living Standard, HTML5 Recommendation, and other sources but haven't found a clear answer. From what I've observed, ...

The utilization of the Open Sans font family results in certain alterations to the user

Currently, I am working on developing a button widget using react. I have utilized the 'Open Sans' font family for the HTML body in order to maintain consistent UI styling. However, some of the styling elements break down when the 'Open Sans ...

Combine multiple .less files into a single .less file without the need for recompilation

I currently have 3 different .less files (1file.less, 2file.less, 3file.less) that I want to combine into a single file called base.less. To import these files into base.less, I am using the @import "1file.less" method. However, upon inspecting the pa ...