Issue with Bootstrap hover and toggle collapse menu functionality in a Ruby on Rails application

I am currently following this tutorial and have reached this particular part. However, I'm facing an issue where the mobile hamburger menu doesn't display the menu when clicked on mobile devices. Additionally, the hover effect is not working for the `dropdown-toggle` element on desktop.

Any assistance would be highly appreciated.

Below is the content of _navigation.html.erb

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="row">

      <!-- Elements visible all the time -->
      <div class="col-sm-7">
        <%= render 'layouts/navigation/header' %>
      </div><!-- col-sm-7 -->

      <!-- Elements collapses on smaller devices -->
      <div class="col-sm-5">
        <%= render 'layouts/navigation/collapsible_elements' %>
      </div><!-- col-sm-5 -->

    </div><!-- row -->
  </div><!-- container -->
</nav>

Here is the content of _header.html.erb

<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapsible-content" aria-expanded="false">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <%= link_to 'User Logins', root_path, class: 'navbar-brand' %>
</div>

Lastly, here is the content of _collapsable-elements.html.erb

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-right" id="navbar-collapsible-content">
  <ul class="nav navbar-nav ">
    <% if user_signed_in? %>
      <li class="dropdown pc-menu">
        <a id="user-settings" class="dropdown-toggle" data-toggle="dropdown" href="#">
          <span id="user-name"><%= current_user.name %></span>
          <span class="caret"></span>
        </a>

        <ul class="dropdown-menu" role="menu">
          <li><%= link_to 'Edit Profile', edit_user_registration_path %></li>
          <li><%= link_to 'Log out', destroy_user_session_path, method: :delete %></li>
        </ul>
      </li>

      <li class="mobile-menu">
        <%= link_to 'Edit Profile', edit_user_registration_path %>
      </li>
      <li class="mobile-menu">
        <%= link_to 'Log out', destroy_user_session_path, method: :delete %>
      </li>

    <% else # user not signed it %>
      <li ><%= link_to 'Login', login_path %></li>
      <li ><%= link_to 'Signup', signup_path %></li>
    <% end # if user is signed it %>
  </ul>
</div><!-- navbar-collapse -->

I believe I have included all necessary information to troubleshoot this issue. If there's anything crucial that I missed, please let me know!

Thank you :)

Edit:

I neglected to include the styling in navigation.scss

body {
 margin-top: 50px;
}

nav {
  .navbar-header {
    width: 100%;
    button, .navbar-brand {
      transition: opacity 0.15s;
    }
    button {
      margin-right: 0;
    }
    button:hover, .navbar-brand:hover {
      opacity: 0.8;
    }
  }
  .col-sm-5, .col-sm-7 {
    padding: 0;
  }
}

.navbar-default, .navbar-toggle:focus, .collapsed, button.navbar-toggle {
  background: $navbarColor !important;
  border: none;
  a {
    color: white !important;
  }
}

.pc-menu {
  margin-right: 10px;
}

.mobile-menu {
  i {
    color: white;
  }
  ul {
    padding: 0px;
  }
  a {
    display: block;
    padding: 10px 0px 10px 25px !important;
  }
  a:hover {
    background: white !important;
    color: black !important;
    i {
      color: black;
    }
  }
}

.icon-bar {
  background-color: white !important;
}

.active a {
  background: $navbarColor !important;
  border-bottom: solid 5px white;
}

.dropdown-toggle, .dropdown-menu {
  background: $navbarColor !important;
  border: none;
}

.dropdown-menu a:hover {
  color: black !important;
  background: white !important;
}

Answer №1

Within the file located at app/assets/javascripts/application.js

It is recommended to remove the following line:

//= require turbolinks

Additionally, ensure that you remove

"data-turbolinks-track" => true from javascript_include_tag.

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

Is it possible to connect ng-model with a style tag?

Is it feasible to create a basic template editor using angularjs where an input field with an ng-model can be connected to a style tag to control the css on an entire page rather than applying it to a specific element with inline styling? Could something ...

Having trouble deleting files in PHP?

I am presenting an HTML form below: <form action='delete.php' method='POST'> <table> <div class = '.table'> <?php $dir = '../uploads/store/'; $new ...

jQuery unable to populate a div with content using the .load method

My goal is to use a jQuery script to grab the content from the "content" class on another page and insert it into the "code" div. Here's the code I'm working with: <script type="text/javascript"> $(document).ready(function() { $(&a ...

Repair copied website data in Excel spreadsheet

I'm currently in the process of extracting a large volume of data from a website. However, when I paste it into Excel, it's not in a table format and appears like this: France Europe Spain Europe Egypt Africa I'm looking for a way to str ...

Struggling with correctly processing values in an HTML PHP Form

Help! I'm struggling with my online PHP form that has checkboxes. When I leave the checkboxes empty and submit the form, the first checkbox option shows up as selected but the second one doesn't (which is correct). Even when I tick both checkboxe ...

What is preventing the textbox from resizing to the full div in IE? Everything looks good in Chrome

Having trouble with IE Resizing? The following code seems simple but it's causing issues: A div containing a text-box that should take up 100% of the DIV while still showing the red border. Unfortunately, setting height and width to 100% causes the bo ...

Using jQuery to Generate an Automatically Updating Timer for Slideshow - Pausing on Mouse Click

My first slideshow with jQuery is up and running, but it's very basic and hard coded. I want to add an automatic scrolling effect every 8 seconds to the next item before looping back to the beginning. I have an idea on how to achieve this, but I want ...

Modify the useRef value prior to the HTML rendering (React functional component)

Hello everyone, I am attempting to update the value of useRef before the HTML is rendered. I have tried using useEffect for this purpose, but it runs after the HTML is ready, making it unsuitable for my needs. What I want to achieve is resetting the value ...

Issues with rendering images in the browser due to CSS inline-block layout are causing

I have encountered an issue with two divs that are set to 50% width and displayed inline-block. Each div contains an image. I expected both divs to stay on the same line, but sometimes the browser breaks the layout. Here is the HTML code snippet: <div ...

What is the best way to turn an entire table into a clickable link that leads to a different HTML page?

I have created a table that I want to turn into a button linking to another page. The table's values need to be changeable based on data from a database, such as changing the parameter to pH and the value to 7. However, the button should redirect to t ...

Iconic Navigation: Bootstrap 3 Navbar featuring Carousel

I'm currently in the process of developing a website using bootstrap3. Despite watching numerous tutorial videos, I am still facing challenges. One of my goals is to have the logo on the navbar aligning with the left side (which I've achieved ...

Why are the radio buttons not aligned with the text in the center?

Currently, I am in the process of building a form that includes radio buttons. However, I've encountered an issue where the text next to the radio buttons appears on a different level than the buttons themselves. How can I go about fixing this partic ...

Unable to delete a dynamically inserted <select> element by using the removeChild method

As someone who is new to coding web applications, I am currently working on a project that involves adding and deleting dropdowns dynamically. Unfortunately, I have run into an issue where the delete function does not work when the button is pressed. Her ...

Connect Angular to a dynamic table of information

Currently delving into Angular and facing an issue where I need to utilize an mvc handler that returns a generic JsonObject. This means the object could be of various types and have different numbers of columns. Rather than statically defining columns in t ...

Odd behavior of dropdown list on Internet Explorer 8

Thank you for taking the time to review this. I have a dynamic dropdown list that changes its content based on a specific value (for example, "51") inputted into the JavaScript code on each page. Different pages display different lists depending on this va ...

Utilize jQuery to extract all values from the second cell of a table and store them in an array

I have a task that involves pushing numbers from text boxes into an array. These text boxes are located in the second cell of each table row, while the third cell contains a date picker. Currently, the code snippet provided retrieves all values from both ...

How is it possible that I am able to view the font on this particular website?

Recently, I stumbled upon a fascinating website that allows users to experiment with various CSS3 features. As I examined the website's CSS code to enhance my own skills, I noticed something intriguing about the elegant "CSS3Gen" logo - it utilized a ...

The art of adjusting list padding and margin to fit varying screen sizes

When dealing with Roman numerals in lists, the width of the numeral can vary significantly from one <li> to another. For example, you may have II next to XVII. I am struggling to find the perfect padding for lists to ensure that wide "bullets" do n ...

Creating a diverse layout by dynamically adding divs without achieving uniformity in the grid

I'm working on dynamically generating a grid of divs with a specific size using the code below: function createGrid(gridSize) { var container = document.getElementById('container'); for (var i = 0; i < gridSize; i++) { va ...

Differences in disabled option value selection between jQuery legacy and updated versions

Recently, I upgraded the jQuery version in my project from 1.7.2 to 2.1.1 and included jquery migrate for fallback support. During testing, I encountered an issue with the value of a select element in jQuery versions 2.1.1 and 1.7.2: For version 1.7.2, t ...