What steps should be taken to create a two-row navbar in Bootstrap 4?

It's really frustrating for me.

This is my bootstrap4 navbar code, and I've tried so many different approaches to creating two rows without success.

Despite inputting the code above, I keep getting the wrong result. I've attempted various solutions, as shown in picture 1, but none have worked.

<nav id="main-nav" class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
    <a class="navbar-brand nav-top" href="<?php echo home_url('/'); ?>">
      <img src="<?php echo render_custom_logo_url(); ?>" style="height: 40px;" class="d-inline-block align-top"><span class="pl-1 d-inline-block" style="font-size: 1.5em;">鴻協資訊耗材商城</span>
    </a>
    <div class="d-flex flex-column flex-wrap">
    <ul class="navbar-nav mt-lg-0 d-none d-md-block">
      <li class="nav-item d-inline-block mr-2 ml-2">
        <a class="nav-link" href="tel:0961588602" role="button"><i class="fas fa-phone pr-1 contact-phone"></i><span class="pr-1"><u>聯絡電話:0961-588602</u></span></a>
      </li>
      <li class="nav-item d-inline-block mr-2 ml-2">
        <a class="nav-link" href="https://line.me/ti/p/iwN_aTYTiR"><i class="fab fa-line contact-line"></i>LINE帳號:pos0961588602</a>
      </li>
    </ul>
    <div>
    <div class="order-2 order-md-3">
      <ul class="navbar-nav mt-lg-0 mr-auto mr-2 inner d-block d-md-none">
        <li class="nav-item d-inline-block mr-2 ml-2">
          <a class="nav-link" href="tel:0961588602" role="button"><i class="fas fa-phone pr-1 contact-phone"></i><span class="pr-1"><u>0961-588602</u></span></a>
        </li>
        <li class="nav-item d-inline-block mr-2 ml-2">
          <a class="nav-link" href="https://line.me/ti/p/iwN_aTYTiR"><i class="fab fa-line contact-line"></i></a>
        </li>
      </ul>
      <ul class="navbar-nav mt-lg-0 ml-auto mr-2 inner">
        <?php global $woocommerce; ?>
        <li class="nav-item d-inline-block mr-2 ml-2">
          <a class="nav-link" href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>"><i class="fas fa-shopping-cart"></i><span class="badge badge-danger" style="vertical-align: super;"><?php echo esc_html( $woocommerce->cart->get_cart_contents_count() ); ?></span></a>
        </li>
      </ul>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main-navitems" aria-controls="main-nav" aria-expanded="false"
      aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
    </div>
    <div class="collapse navbar-collapse order-3 order-md-2" id="main-navitems">
      <?php
      wp_nav_menu(array(
        'menu' => 'main_menu',
        'theme_location' => 'main_menu',
        'container' => false,
        'menu_id' => 'mainMenu',
        'menu_class' => 'navbar-nav mt-lg-0 mr-auto ml-2',
        'depth' => 2,
        'fallback_cb' => 'bs4navwalker::fallback',
        'walker' => new bs4Navwalker()
      ));
      ?>
      <form id="navSearchMobile" class="d-md-none" role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
        <div class="input-group">
          <input name="s" class="form-control form-control-sm" type="search" placeholder="輸入商品名稱" required>
          <span class="input-group-btn">
            <button class="btn btn-outline-success btn-sm" type="submit">搜尋</button>
          </span>
        </div>
      </form>
    </div>
    <form id="navSearch" class="form-inline my-2 my-lg-0 order-md-4 d-none d-md-flex" role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
      <div class="input-group">
        <input name="s" class="form-control form-control-sm" type="search" placeholder="輸入商品名稱" required>
        <span class="input-group-btn">
          <button class="btn btn-outline-success btn-sm" type="submit">搜尋</button>
        </span>
      </div>
    </form>
    </div>
    </div>
</nav>

What should I do to solve this issue?

I simply want to display two rows on a PC like Picture 1, and on mobile like Picture 3.

Answer №1

If you want to display your content in the navbar in full-screen mode, you can use the following code:

<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
  <a class="navbar-brand nav-top" href="<?php echo home_url('/'); ?>">
      <img src="<?php echo render_custom_logo_url(); ?>" style="height: 40px;" class="d-inline-block align-top"><span class="pl-1 d-inline-block" style="font-size: 1.5em;">Your Company Name</span>
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
     <div class="collapse navbar-collapse" id="navbarText">
    <ul class="navbar-nav mr-auto">
       <li class="nav-item d-inline-block mr-2 ml-2">
        <a class="nav-link" href="tel:0961588602" role="button"><i class="fas fa-phone pr-1 contact-phone"></i><span class="pr-1"><u>Contact Phone: 0961-588602</u></span></a>
      </li>
        <li class="nav-item d-inline-block mr-2 ml-2">
        <a class="nav-link" href="https://line.me/ti/p/iwN_aTYTiR"><i class="fab fa-line contact-line"></i>LINE ID: pos0961588602</a>
      </li>
      <li class="nav-item d-inline-block mr-2 ml-2">
          <a class="nav-link" href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>"><i class="fas fa-shopping-cart"></i><span class="badge badge-danger" style="vertical-align: super;"></span></a>
        </li>

    </ul>
      <span class="navbar-text">
         <form class="form-inline " style="right:0">
            <div class="search-block" style="display:inline-block;position:relative;">
      <div class="form-input-icon form-input-icon-right">
        <i class="fas fa-search"></i>
         <input name="s" type="search" class="form-control form-control-sm form-control-rounded" placeholder="Enter Product Name" required >
       <button type="button" class="search-block-submit"></button>
    </div>
    </div>

  </form>
  </span>
  </div>


</nav>

I have also updated the search input so that the search button stays aligned properly. You can view my solution and the accompanying CSS styling in this Plunker link.

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

Steps for closing the menu by clicking on the link

My issue with the menu on the landing page is that it only closes when clicking the cross button. I want it to close when any link from the menu is clicked. I attempted to add code using querySelector, but it only worked for the home link and not the other ...

`Flex alignment of columns in Bootstrap 4`

I'm feeling really lost here. I had everything figured out, but after refreshing the jsfiddle, the solution suddenly changed on me. I have a row with two columns in it, but for some reason, I can't get them to align properly on the same row. I at ...

Angular 4: Automatically dismiss modal once form submission process is complete

My Bootstrap 4 modal closes properly when I press the close button. However, I want the modal to close after submitting the create button in the form. I am using Angular 4. <div class="modal fade" id="createLabel" tabindex="-1" role="dialog" aria-label ...

What is the best way to adjust the width of a div based on the remaining space in the viewport?

I've created a Wireframe to showcase the concept I'm aiming for. There are 2 screens included to illustrate how the layout should adapt to different screen sizes. Check out the Wireframe here The goal is to have a center-aligned container named ...

Is it possible to utilize the same module.css file across multiple components in a React project?

As a newcomer to React, I have discovered the benefits of using module CSS to address naming conflicts. Now, as I prepare to refactor my app, I have encountered a scenario where two components are utilizing styles from the same file. I am curious to lear ...

Sprite is being enlarged instead of being cut off

After successfully implementing rollover images, the code suddenly stopped working when I added a modal popup for another button on the site. I removed the modal pop-up, but now the sprites are broken. Instead of showing the light banner and dark hover eff ...

What is the process of integrating Bootstrap into an ExpressJS project?

Working on a project with nodejs and Express framework, I am looking to incorporate Bootstrap locally. I have included the following in the <head> of my index file: <script language="javascript" src="../node_modules/bootstrap/dist/js/bootstrap.mi ...

Creating a unique custom form using Bootstrap 4 and the Simple Form plugin

With the introduction of Bootstrap 4, custom forms have been added to allow for a more personalized look for checkboxes and radio buttons. How can we create these templates using Simple Form? Custom Checkbox: <label class="c-input c-checkbox"> & ...

Accessing unique <a href> attributes within ASP.NET code behind using Twitter Bootstrap

Currently, I am in the process of developing a website using Twitter Bootstrap and ASP.NET. Within Bootstrap, there are built-in modal window controls that can be accessed through an anchor tag formatted like this: <a data-toggle="modal" href="#catalog ...

Tooltip remains visible even after formatting in highcharts

I have successfully hidden the datalabels with 0 values by formatting them. However, after formatting the tooltips for 0 valued data in a pie chart, there is an issue where hovering over the 0 valued portion shows a white box as shown in the picture. I hav ...

Issue with Google Chrome not showing stylesheets on Windows 7

Recently, I've been facing an issue with CSS layers on my website while using Google Chrome. Despite following the code accurately, my browser fails to display the expected result. To troubleshoot, I even copied and pasted code from a reliable source ...

Personalized Grid Design for Showcasing Athletic Teams

I am looking to create a custom grid layout that represents the team's Players, separated by their positions (GK, Defense, Midfielders, and Forwards), similar to the image below. The layout should also be responsive like in image 1. Currently, the re ...

Creating a div that spans the entire height from top to bottom

Currently, I am faced with the following scenario: <div id=area> <div id=box> </div> </div> <div id=footer> </div> The "area" div is situated in the center and has a width of 700px with shadows on both the right and ...

Which specific transitionend (or animationend) event should I use for this application?

I'm feeling a bit lost when it comes to using transitionend (or if I should be using animationend in this scenario). I'm not sure whether to utilize var, node, or box. Essentially, I am a complete beginner in this case. My goal is to have my div ...

What is the reason for parent rows not stretching fully across the width of the page?

I am working on creating a simple table in Vue.js with Bootstrap. When the arrow is clicked, the child row is displayed, and I want it to appear below the parent row. I achieved this by setting display:flexbox; flex-direction:column; Here is the HTML tabl ...

Step-by-step guide on replicating the style of a div class

I'm attempting to create a comments counter div that changes color based on the number of comments. If there are 0 comments, the div should be red, and if there are more than 0 comments, the div should be blue. However, I am encountering an issue with ...

Troubleshoot: Problem with iPhone Orientation on Bootstrap Framework

While working on a responsive website design, I encountered an issue that needs addressing. Initially, switching from portrait mode to landscape didn't trigger the expected responsive behavior; instead, it simply zoomed into the site. To prevent this ...

What is the best way to close an ajax page within the main page using a button?

I am dealing with a situation where I have 2 pages. The first page contains a div called 'ajaxicall', which loads another page inside it. The challenge I am facing is figuring out how to close the second page when I click on the "close" button w ...

What causes webkit browsers to reduce the size of certain floating elements on mobile devices?

Struggling to create a responsive layout for a web app, specifically dealing with rendering issues on mobile webkit browsers. The floating elements are shrinking in an unpredictable way, causing problems on Chrome and Safari for Android and iOS devices. ...

Is it possible to customize the borders of boxes in Google Charts Treemap?

Although this may seem like a minor issue, I can't find any information in the documentation. I'm currently using Google Charts treemap for monitoring a specific project. The problem I'm facing is that when all the parent level rectangles ar ...