Tips for arranging items to appear in a dropdown menu instead of in a horizontal row on the navigation bar using Bootstrap 4

Sorry if this seems like a basic inquiry, but I'm still learning about bootstrap 4 and haven't had any luck finding the solution online.

My issue involves a navigation bar with three columns: logo on the left, small menu in the center, and a logout button on the right. However, when the screen size shrinks to between 550px and 767px, instead of wrapping onto a new line, everything just gets compressed and spills off the page. I've tried disabling styles in the console without success. The only workaround I found was removing the navbar class from the navigation element, but that messes up the layout on other screen sizes, so it's not a viable fix.

Below is my HTML code. Can anyone guide me in the right direction? I aim for a design similar to this (logo above menus):

Logo

Menu 1 | Menu 2 | Menu 3 | Menu 4 Logout

html:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
    <div class="container">
        <a class="navbar-brand" href="/">Logo</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
            <ul class="navbar-nav">
                <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">
                        Name
                    </a>
                    <div class="dropdown-menu text-center dropdown-logout" aria-labelledby="navbarDropdown">
                        <form action="" method="post">
                            <button type="submit" class="btn btn-primary">Logout</button>
                        </form>
                    </div>
                </li>
                <li class="nav-item">
                </li>
            </ul>
            <ul class="navbar-nav flex-grow-1">
                <li class="nav-item">
                    <a class="nav-link btn-ghost-blue" href="/#">Menu 1</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link btn-ghost-blue" href="/#">Menu 2</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link btn-ghost-blue" href="/#">Menu 3</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link btn-ghost-blue" href="/#">Menu 4</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Appreciate your help!

Answer №1

If you're looking to avoid utilizing the bootstrap 4 responsive navbar from their documentation because you prefer not to collapse your navbar on small screens, you may opt to create your own personalized responsive navbar.

As previously mentioned in the comments, you can utilize the grid system to adjust the column size accordingly for various screen sizes. The snippet provided below can offer you some inspiration, simply run it in full screen and resize your window.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<nav class="navbar navbar-light flex-nowrap flex-row">
    <div class="container">
      <div class="row w-100">
        <div class="col-12 col-sm-auto">
        <a href="/" class="navbar-brand">Logo</a>
        </div>
        <div class="col-12 col-sm-auto">
          <ul class="nav navbar-nav flex-row">
              <li class="nav-item"><a class="nav-link pr-3" href="">Login</a></li>
              <li class="nav-item"><a class="nav-link" href="">Sign up</a></li>
        </ul>
       </div>
      </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

I'm seeking a way to access the input element within the InputGroup component of BlueprintJs in my

The BluePrintJS React InputGroup component offers a convenient user interface for modern applications. However, it does not provide direct access to the internal <input> element. There are two primary reasons why I need to access the input element: ...

Bootstrap grid button with maximum flexibility

I am currently exploring the intricacies of the bootstrap grid system. My goal is to create a set of buttons that look like this: https://i.sstatic.net/V5meG.png Each button should expand to fill the width and height of its container. However, when a b ...

I am attempting to achieve a smooth transition effect by fading in and out the CSS background color using JQuery and AJAX

Can anyone help me with my issue related to using Ajax to fadeIn a background color in beforeSend and fadeOut in success? I seem to have made some mistakes but can't figure out what went wrong. var data={ ...

The Bootstrap switch feature may encounter issues when trying to operate on dynamically generated checkbox inputs

My website is equipped with a mix of essential scripts: jQuery, Bootstrap, Modernizer, and JSON2HTML. I am trying to implement the following code snippet: <script> $('#my01Switch').bootstrapSwitch({ onText: 'ON', ...

Find and make adjustments to the primary HTML document in your Magento online shop

Trying to enhance the top banner of my Magento website tamween.biz by adding a shadow effect PNG picture. Successfully managed this on my local server using firebug and creating a new class in the coding area with all selector properties modified in the bo ...

Why is the Google Map missing from the Bootstrap modal dialog?

I have multiple links on my website, each describing a different location with unique map data. I would like to display a modal bootstrap dialog with an embedded Google map when a user clicks on any of the links - ensuring that the location shown correspon ...

Review a roster of websites every half a minute (Revise pages every half an hour??)

Just starting out with HTML coding! Can someone please provide the code that will allow me to save various webpages and automatically cycle through them every 30 seconds? And also ensure that the webpages are updated every 30 minutes. ...

Utilizing flexbox to create spacing between elements and ensuring there are no margins on the parent

Discover a Codesandbox demo at: https://codesandbox.io/embed/silly-firefly-87cov A unique challenge awaits with this project - elements within the parent container are positioned dynamically using flexbox. But how can we apply margins selectively only bet ...

``How can I easily navigate to the top of the page when changing routes in React Router DOM v6?

What is the best way to scroll to the top when a route changes in react router dom v6? In the past, I used a solution from this StackOverflow post to make my page automatically scroll to the top every time a route changed with react-router-dom v5. However ...

displaying information from foreach loop in a vertical column format rather than horizontally

Currently, I'm attempting to retrieve data from a database using a foreach loop and display it in columns. However, the output I'm getting is not formatted as I desire. Check out how it's appearing currently https://i.sstatic.net/JVMLq.png ...

Tips for achieving a gradual transformation of an element according to the scrolling position

I have been experimenting with using waypoints for two specific purposes. The first objective is to determine whether a user is scrolling up or down and if the container comes into view. However, this functionality is not working as expected. The sec ...

When I included the `<body href="~/"/>` tag in my _Layout.cshtml file, it resulted in a Blazor Error stating: Circuit host not initialized

Currently, I am developing an Asp.net Core web application in visual studio. I have created a razor component that displays some data and includes a button with a function to update a variable that changes the UI. To give my razor component its functionali ...

The element is not centered on the page, even though it is positioned at 50%

My hover popup is positioned absolutely with a left value of 50%. Despite this, it does not appear in the center of the page as expected when hovering over the "ice white" image. Can anyone offer suggestions on how to fix this issue? Thank you in advance ...

The values are failing to transfer to the table after submitting the information on the form

I'm experiencing issues with my code as some parts are not functioning correctly. While the HTML and CSS sections are working fine, the problem lies in the AngularJS part. When I input data into the form above, I need the employee details to be sent t ...

What is the best way to smoothly enlarge a div as new content is introduced?

Is there a way to smoothly expand a div when new content is added? const [render, setRender] = useState(false) const showHide= () => { setRender(!render) } return ( <div className="container"> <h1>TEST ...

Display additional information in a sidebar when hovering over it

I stumbled upon a sidebar code that caught my interest: #sidebar { position: fixed; z-index: 10; left: 0; top: 0; height: 100%; width: 60px; background: #fff; border-right: 1px solid #ddd; text-align: center; } #sidebar a { text-d ...

Ensuring the same height for the navigation bar and logo with aligned vertical text

I'm in the process of recreating a simple navigation menu and I've reached the section where I am encountering an issue with the list items. The orange li element is not filling up 100% of the width, and I also need the links to align in the midd ...

Is it necessary to execute a function prior to sending a fetch request?

A new challenge I'm facing involves creating a vanilla JavaScript weather app. I want the app to request the user's location with their permission and use it in a fetch call as a template string, which will then determine their location and displ ...

The hover effect does not function on an SVG element when it is placed within an external file

I've been experimenting with SVG animation. My goal is to change the color of a circle when it's hovered over. <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 437 ...

Utilize Java to launch the HTML file in a web browser

I have a specialized need for my HTML files to be displayed on a platform that is browser-free. The solution that immediately comes to mind for me in this scenario is utilizing applet. Therefore, I am interested in having my HTML file (including CSS and JS ...