Challenges migrating from Bootstrap 3 to Bootstrap 4

My current challenge involves updating some code that previously worked with a version of Bootstrap 3 and now I am transitioning to version 4.3.1. Specifically, I am working on altering the navbar code, which has undergone significant changes from version 3 to version 4, leading to a number of issues.

Although I referred to... https://getbootstrap.com/docs/4.0/migration/, which outlines the migration process to version 4, I am still unable to make it work correctly.

<nav class="navbar navbar-light navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false" style="margin-top:17px; background-color:white; opacity: 0.7;">
          <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 image_tag("logo.svg", size:"150x59"), store_index_path, :class => "navbar-brand", method: :get %>
      </div>
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1" >
        <ul class="nav navbar-nav">
          <li><%= link_to t('.questions'), store_index_path, class: "navbar_main_links" %></li>
          <li><%= link_to t('.news'), store_index_path, class: "navbar_main_links" %></li>
          <li><%= link_to t('.contact'), store_index_path, class: "navbar_main_links" %></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/Cog_font_awesome.svg/512px-Cog_font_awesome.svg.png" alt="gear"> </a>
            <ul class="dropdown-menu">
              <% if session[:user_id] %>
                <li><%= link_to "Orders", orders_path, class: "navbar_main_links" %></li>
                <li role="separator" class="divider"></li>
                <li><%= link_to "Products", products_path, class: "navbar_main_links" %></li>
                <li role="separator" class="divider"></li>
                <li><%= link_to "Users", users_path, class: "navbar_main_links" %></li>
                <li role="separator" class="divider"></li>
                <li><%= link_to "Logout", logout_path, method: :delete, class: "navbar_main_links" %></li>
              <% else %>
                <li><%= link_to "Login", login_path, class: "navbar_main_links" %></li>
              <% end %>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><img src="https://image.flaticon.com/icons/png/512/61/61027.png" alt="gear" id="navbar_image_locale"> </a>
            <ul class="dropdown-menu">
              <% LANGUAGES.each_with_index do |language, index|%>
                <li><a href=""><%= link_to language[0].to_s, store_index_url(locale: language[1]), class: "navbar_main_links" %></a></li>
                <% if index != LANGUAGES.size-1 %>
                  <li role="separator" class="divider"></li>
                <% end %>
              <% end %>
            </ul>
          </li>
        </ul>
        <form class="mx-2 my-auto d-inline w-100">
          <%= form_tag(store_index_path, method: :get) do %>
            <%= text_field_tag :search, '', class: 'form-control border border-right-0' %>
            <%= image_submit_tag "https://cdn1.iconfinder.com/data/icons/flat-web-browser/100/search-512.png", id: "navbar_search_image_submit" %>
          <% end %>
        </form>
      </div>
    </div>
  </nav>

Despite making several adjustments, the rendered output still only displays the image file from the ERB code and a checkbox that triggers the collapse dropdown function.

I suspect that I might be using a deprecated class or encountering a similar issue, but I am unable to pinpoint the exact cause.

Any assistance on resolving this matter would be greatly appreciated :)

Answer №1

Migration Issue.

It appears that many of the classes you are utilizing are not available in version 4. I recommend either copying the template from Bootstrap and using it, or checking if the class name you are using exists in version 4, especially if you are using an editor like Intellij.


This layout is similar to yours.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
 <a class="navbar-brand" href="#">
    <img src="" width="30" height="30" alt="">
  </a>
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <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">
          Dropdown
        </a>
        <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
          <li class="dropdown-item">Action</li>
          <li class="dropdown-item" >Another action</li>
          <li class="dropdown-divider"></li>
          <li class="dropdown-item">Something else here</li>
        </ul>
      </li>
      <li class="nav-item">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
          <li class="dropdown-item">Action</li>
          <li class="dropdown-item" >Another action</li>
          <li class="dropdown-divider"></li>
          <li class="dropdown-item">Something else here</li>
        </ul>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

https://codepen.io/anon/pen/mYZjNv

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

What is the best way to maintain the selected radio button on the following page using PHP?

Image of My Project I am working with a file and need some assistance. I want to ensure that when a user selects an answer, the radio button value remains unchanged if they click back. Can someone please help me with this? while( $row = mysqli_fetch_arra ...

Implement a fullscreen hero image on a specific blogroll template page in Wordpress

My portfolio website uses custom page templates for each page. The blog page is not the landing page, but an interior page. I have been able to add a custom hero image to every page template except for the blog page. Currently, I am using the content.php p ...

Aligning Font Awesome icons inside md-buttonsFinding the perfect alignment for

I am attempting to center font awesome icons within a button so that they align perfectly with the text on a toolbar. Below is the code snippet I am working with: <div ng-app="app"> <md-toolbar> <div class="md-toolbar-tools" md-tall ...

Restrictions on the number of characters based on the size of fonts in an html list sc

Recently, I attempted to implement a ticker message on my website using li scroller. However, it appears that there is a limitation on the number of characters that can be displayed in the ticker message when different font sizes are used. With a smaller ...

Scanning barcode and Qrcode with Angular js HTML5 for seamless integration

Looking to scan Barcode and Qrcode on Android, iPhone, and iPad devices for a project that is built on AngularJS and HTML5 as a mobile website. The requirement is not to download any third-party native application on the device, ruling out the use of nati ...

Delaying Jquery on scroll Event

Hey there, I've got a set of icons that I'd like to reveal one by one as you scroll down. I've incorporated some animations from , but now I'm wondering how I can implement a delay function in my jQuery so the icons appear sequentially ...

Tips for keeping your avatar contained within a Bootstrap grid

I am attempting to adjust the positioning of my "image holder" (avatar) with a top and bottom margin of 3px, but when I implement this change, the image holder shifts outside of the grid. Below is the code snippet in question: <div class="container con ...

iTextSharp struggles to convert certain HTML elements to PDF format

After experimenting with the codes provided in this post, I managed to create the following code snippet: var my_html = this.GetmyReportHtml(); var my_css = this.GetmyReportHtmlCss(); Byte[] bytes; using (var ms = new MemoryStream()) { ...

"Choosing the text within an <a> tag: A step-by

I am dealing with the a tag. <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4c7dbd9d1f4d9d5ddd89ad7dbd9">[email protected]</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Differences in functionality across various browsers when dealing with complex subgrid structures

After nesting a subgrid inside a padded subgrid within a grid, I noticed varying behavior across different web browsers. Chrome/Edge (Windows) Firefox (Windows) Safari MacOS https://i.stack.imgur.com/uHlto.png https://i.stack.imgur.com/SGxuC.png ht ...

Moving data of a row from one table to another in Laravel by triggering a button click

For instance, consider a scenario where clicking a button moves a row to another table in the database and then deletes it. Implementing this functionality in Laravel seems challenging as I am unable to find any relevant resources or guidance on how to pro ...

Animate a div once the parent section becomes visible while scrolling

I previously had this function working, but it seems that I have somehow messed it up in the process. My current setup includes a scroll hijack feature that navigates users to a new section or card each time they scroll. The script adds a visible class w ...

Is there a way to eliminate the whitespace beneath the "Brilliant" division?

[Screenshot of white space under div] [1]: https://i.sstatic.net/cO7TV.jpg I'm having trouble figuring out why there is visible white space here. As a coding beginner, I would really appreciate any assistance. I've tried searching for the soluti ...

To create a distinctive design, the HTML5 wrapper will specifically enclose the Header element

After using a border, I discovered that my wrapper is only wrapping the header and not extending down to the footer. Can anyone offer some guidance on how to wrap the entire content from the header to the footer? I've come across suggestions to speci ...

The grid images transition at set intervals using jQuery or another JavaScript framework

I am facing a challenge with developing an image grid that transitions some images at random intervals using either jQuery or another method in JavaScript. It's important to note that I don't want all the images to change simultaneously; each gro ...

Concealing the view-source feature in core PHP or HTML

Is there a way to conceal view-source in basic php or html? I've come across some information on this topic, but I'm having trouble grasping how to implement it: Web Developer Class: How to Hide your Source Code ...

Turn off the Antd Datepicker tooltip

I'm using Antd Datepicker in my website. We get an array of numbers representing disabled dates from an external api and show only the dates in the datepicker(no month, year etc). The date selection is for a monthly subscription and the user just sele ...

The animation unexpectedly resets to 0 just before it begins

Currently, I am developing a coverflow image slider with jQuery animate. However, there are two issues that I am facing. Firstly, when the animation runs for the first time, it starts at `0` instead of `-500`. Secondly, after reaching the end and looping b ...

Steps for aligning two input elements side by side in Bootstrap 4

I need help positioning the text input and button side by side, with a margin of about 10px between them. The code I have right now is producing the result shown in the attached photo. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/c ...

Bootstrap CSS: image is overlapping text inside a div

In my layout, I have four inner div containers arranged as follows: small picture - text - small picture - text. <div class="container"> <div class="col-md-12"> <div class="row"> <div class="col-sm-2"> <div c ...