Tips for creating a responsive navbar image alongside your navbar

On my desktop, the navbar appears perfectly. However, when I switch to mobile view, the navbar image does not fit properly and the hamburger menu is missing. See the image below:

View Image Here

After refreshing the page, the hamburger menu finally shows up:

View Image Here

I'm not sure if this issue is related to Rails, but it seems like I have to refresh the page to get the hamburger icon to display on the mobile navbar.

<header id="header-wrap">
  <!-- Navbar Start -->
  <nav class="navbar navbar-expand-lg fixed-top scrolling-navbar">
    <%= link_to image_tag("logo2.png", alt: "Brand"), root_path, :class=>'navbar-brand' %>
    <div class="container">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
          <span class="lni-menu"></span>
          <span class="lni-menu"></span>
          <span class="lni-menu"></span>
        </button>
      </div>
      <div class="collapse navbar-collapse" id="main-navbar">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item dropdown active">
            <%= link_to 'Home', root_path, class: 'nav-link dropdown active' %>
          </li>
          <li class="nav-item">
            <%= link_to 'Categories', categories_path, class: 'nav-link' %>
          </li>
          <li class="nav-item dropdown">
            <%= link_to 'Business Directory', business_directory_path, class: 'nav-link dropdown-toggle' %>
          </li>
          <li class="nav-item dropdown">
            <%= link_to 'Partners', partner_path, class: 'nav-link dropdown-toggle' %>
          </li>
          <li class="nav-item">
            <%= link_to 'News & Tech', blogs_path, class: 'nav-link' %>
          </li>
        </ul>
        <ul class="sign-in">
          <% if user_signed_in? %>
            <li class="nav-item dropdown">
              <%= link_to 'My Account', edit_user_registration_path, :class => 'nav-link dropdown-toggle', 'aria-haspopup' => 'true', 'aria-expanded' => 'false' %>
              <div class="dropdown-menu">
                <%= link_to 'My Ads', myads_path, class: 'dropdown-item' %>
                <%= link_to 'Inbox', conversations_path, class: 'dropdown-item' %>
                <%= link_to 'Settings', edit_user_registration_path, class: 'dropdown-item' %>
                <%= link_to 'Logout', destroy_user_session_path, method: :delete, :class => 'dropdown-item' %>
              </div>
            </li>
          <% else %>
          <li class="nav-item">
            <%= link_to 'Login / Signup', new_user_session_path, :class => 'nav-link dropdown-toggle' %>
          </li>
          <% end %>
        </ul>
        <%= link_to 'Post Ad', new_post_path, :class => 'tg-btn' %>
      </div>
    </div>

    <!-- Mobile Menu Start -->
    <ul class="mobile-menu">
      <li>
        <%= link_to 'Home', root_path, class: 'active' %>
      </li>
      <li>
        <%= link_to 'Catgeories', categories_path %>
      </li>
      <li>
        <%= link_to 'Business Directory', business_directory_path %>
      </li>
      <li>
        <%= link_to 'Partners', partner_path %>
      </li>
      <li>
        <%= link_to 'News & Tech', blogs_path %> 
      </li>
      <li>
        <%= link_to 'Post Ad', new_post_path %> 
      </li>
      <li>
        <% if user_signed_in? %>
        <%= link_to 'My Account', edit_user_registration_path %>
        <ul class="dropdown">
          <li><%= link_to 'My Account', edit_user_registration_path %></li>
          <li><%= link_to 'My Ads', myads_path %></li>
          <li><%= link_to 'Settings', edit_user_registration_path %></li>
          <li><%= link_to 'Logout', destroy_user_session_path, method: :delete %></li>
        </ul>
        <% else %>
        <%= link_to 'Login / Signup', new_user_registration_path %>
        <% end %>
      </li>
    </ul>
    <!-- Mobile Menu End -->

  </nav>
</header>

Below is the contents of my application.js file:

//= require rails-ujs
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require jquery.slick
//= require local-time
//= require summernote/summernote-bs4.min
//= require summernote-init
//= require social-share-button
//= require activestorage
//= require turbolinks
//= require_tree .

Answer №1

For the navbar image to be responsive, make sure to add an extra class. If you're working with bootstrap 3, include .img-responsive; for bootstrap 4, use .img-fluid. This should solve your issue!

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

Adjusting background position using incremental changes through JavaScript

Although I have a strong background in PHP coding, using javascript is a new venture for me so I hope this question doesn't sound naive. My objective is to create a button that, when clicked, shifts the background-position of a specified DIV object b ...

Positioning the jQuery mobile navBar to be fixed on iOS 4 devices

Currently working on a mobile app with jquery using iOS4 and iOS5 compatibility as the final hurdle. While fixing the navigation bar is simple on iOS5 with position:fixed, it's not as straightforward on iOS4! I've experimented with various soluti ...

Concentrate and essential

I am encountering an issue with required inputs and the :focus styling on those inputs. When I try to submit empty values, the red border from the required styling appears and does not disappear when I click on the input. As a result, I end up with a stran ...

Challenge encountered while processing JSON data

I've searched through various threads and tutorials, but I'm still stuck on this issue! I have two JSON responses that need to be utilized in separate functions: 1st (single element) Need to extract "Intention_category" and "count" Data: { " ...

Text in gray overlaying image background

I am attempting to design a layout that resembles the following: https://i.sstatic.net/S5CCK.jpg Although I can create the letter "A" using svg or clip-path, my challenge lies in maintaining the background inside the "A" aligned with the body background. ...

Is JQuery Mobile panel still not functioning properly with JQuery 2.0.3?

Experiencing issues with loading JQM panels. Using Jquery v2.0.3 and JQM v1.3.2. The JS console is showing the following error: Uncaught TypeError: Cannot read property 'options' of undefined Line# jquery.mobile-1.3.2.js:10330 After some resea ...

Using Ajax URL in a Wordpress Plugin

Plugin Class File: function __construct() { add_shortcode('user_registration_form', array( $this, 'shortcode' )); } public function hook() { add_action('wp_ajax_get_product_serial_callback', 'get_product_se ...

Avoid refreshing AJAX on browser back navigation

Describing my current situation: I have a scenario with 2 pages: - On page 1, it sends a request using $.ajax to receive JSON data for display. Then there is a button that when clicked, takes me to page 2. - After clicking the button and transitionin ...

The ASP.NET form does not display the md-button in the appropriate size

I have an ASP.NET form where I am trying to insert a md-button, but the button seems to resize and does not fit the row as desired. I have searched for documentation on this issue, tried adjusting the layout of the button, placing it in a md-input-contain ...

ScrollMagic : The JQuery element appears to be malfunctioning as a triggerElement

While reviewing the documentation The definition of triggerElement requires a selector, DOM object, or jQuery Object to indicate the start of the scene. If left undefined, the scene will commence at the beginning of the page (unless an offset is speci ...

Constructing a React component with a constructor

I am brand new to working with react native and I'm requesting assistance in fixing the code below. Currently, I have a view within a const and I am looking to include a constructor inside the const function. const { width } = Dimensions.get(' ...

Triggering the onChangeMonthYear() event manually for jQuery datepicker

Currently, I am working with this function: $('#picker').datepicker({ // ... onSelect: function(currDate){ } }); I would like to manually trigger the onSelect() function, but using $('#picker').datepicker.onSelect(); does ...

Guide to positioning an image next to text within a table: Utilizing jQuery DataTable to organize images alongside text in a table header

When using the jQUery DataTable plugin, I encountered an issue where the table header text and the image for sorting are not properly aligned. Here is how it looks: https://i.sstatic.net/Kqgz9.png (I want the arrow and the text to be aligned horizontally ...

Using just a simple HTML code, the d-flex feature in Bootstrap seems to be malfunctioning

Embarking on a new Bootstrap website project has presented me with a challenge that I have not been able to overcome, even with minimal HTML and just one flex item (which happens to be the only element on the site): <!DOCTYPE html> <html lang=" ...

What could be causing ngInfiniteScroll to not work properly with tables?

I've been attempting to incorporate ngInfiniteScroll into my table using ng-repeat on <tbody> however, it isn't triggering when I reach the end of the page. <div infinite-scroll="list.getMoreItems()"> <table md-table md-row-se ...

Can someone provide assistance on how to add an icon to a button?

Help needed with adding icons to buttons! I am new to coding and struggling with adding icons to each button. If any classes need to be changed, please let me know. I am currently learning HTML and CSS and could use some guidance. Thank you! Example: ...

Inquiring about the rationale behind using `jquery.ui.all.css` specifically

I'm curious about the impact of jquery.ui.all.css on Tabs As soon as I remove it, <link rel="stylesheet" href="jquery/dev/themes/base/jquery.ui.all.css"> My tabs stop functioning. Here's my query: What exactly does the jquery.ui.all.cs ...

Is there a way to obtain the coordinates of an SVG element by simply clicking on a specific point?

I'm still learning about SVG and I'm trying to trigger an event that captures the click coordinates when clicking on the SVG. I have a few questions: Since I'm using Angular, I'm unsure if it's possible to keep my function in th ...

What is the best way to increase the height of a div up to a specific point before allowing it to scroll?

Is there a way to make a div expand to fit its contents up to 250px and then scroll if necessary? I attempted using the following CSS: text-overflow: ellipsis; max-height: 250px; overflow-y: scroll; However, this solution doesn't achieve the desired ...

Submitting a Form with Ajax and JQuery in .NET

Thanks to the help of balexandre and rtiq, I have successfully figured out the flow. My .ashx file is being called, indicating that a portion of the code is functioning correctly, although an error is being alerted. However, when I trace the .NET, the vari ...