Struggling to implement Bootstrap grid in a Rails project

I'm encountering a problem similar to what was discussed in Issue with Bootstrap grid in Rails (and other related threads), but the suggested solution isn't resolving my issue. Despite using Bootstrap 3 classes with the Bootstrap 3 gem, I'm unsure why it's still not functioning properly.

My Gemfile includes:

gem 'bootstrap-sass', '~> 3.1.1.0'
gem 'sass-rails', '~> 4.0.0'

In custom.css.scss:

@import "bootstrap";

application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <title>TEi-LS Data Tracker</title>
  <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
  <%= render 'layouts/shim' %>
</head>
<body>
    <%= render 'layouts/header' %>
    <div class="container">
      <% flash.each do |key, value| %>
        <%= content_tag(:div, value, class: "alert alert-#{key}") %>
      <% end %>
      <%= yield %>
      <%= debug(params) if Rails.env.development? %>
    </div>
</body>
</html>

home.html.erb:

<div class="row">
    <div class="col-md-4">1</div>
    <div class="col-md-4">2</div>
    <div class="col-md-4">3</div>
</div>
<div class="row">
    <div class="col-md-4">4</div>
    <div class="col-md-4">5</div>
    <div class="col-md-4">6</div>
</div>

Instead of displaying as a grid, the output appears stacked vertically:

1
2
3
4
5
6

This is my first time posting a question, so hopefully I've provided enough detail. Appreciate any assistance you can offer. Thank you.

Answer №1

To properly structure your home.html.erb file, it is essential to include a container element within it.

<div class = "container">
    <div class="row">
        <div class="col-md-4">1</div>
        <div class="col-md-4">2</div>
        <div class="col-md-4">3</div>
    </div>
</div>

Remember to also make necessary adjustments in your custom.css.scss file:

@import "bootstrap-sprockets";
@import "bootstrap";

Additionally, modifications are needed in your application.css file:

*= require_tree .
*= require_self
*/

It is worth noting that Bootstrap relies on JavaScript functionalities. If you encounter issues like a non-functional navbar class, ensure you have included the required sprocket js file in your application.js:

//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .

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

Ways to modify the color of table fonts and contents using inline CSS

I would like some help changing the color of the alphabet in my table. Here is the current format: <table border="1" background="images/haya1.jpg" cellpadding="5" cellspacing="10" width="30%" align="center" bordercolor="brown" bgcolor="red"> & ...

What is the best way to utilize jQuery in order to present additional options within a form?

Let's consider a scenario where you have an HTML form: <form> <select name="vehicles"> <option value="all">All Vehicles</option> <option value="car1">Car 1</option> <option value="car2">Car 2< ...

Floating Action Button is not properly attached to its parent container

When developing my React Js app, I decided to utilize the impressive libraries of Material UI v4. One particular component I customized is a Floating Action Button (FAB). The FAB component, illustrated as the red box in the image below, needs to remain p ...

Unable to apply box-shadow styling to input elements

Why am I having trouble adding box shadows to input elements in my CSS? I've tried something like this http://jsfiddle.net/DLCTh/, and while it applies correctly to div elements, it doesn't seem to work on text inputs. Am I overlooking something ...

Tips for customizing the appearance of a Bootstrap toggle switch

I'm struggling to customize my bootstrap toggle button. No matter what I try, I can't seem to make any styling changes take effect. All I really need to do is increase the width of the button, but even that seems impossible. Here's a link t ...

Tips for properly positioning and rotating text in CSS and HTML!

My goal is to place a rotated headline next to some text, but I'm facing challenges with positioning when the page is resized. While absolute positioning works easily in a static scenario (left picture), it fails when the page size changes (right pict ...

What is the best way to use CSS 3 to resize and enlarge an image, such as sprite icons?

Hello everyone, Picture this: a sprite image named icons.png linked to the css class .icons, featuring various 10x10px graphics. Now imagine needing another class that enlarges these sprite graphics exactly twice their size, making them 20x20 pixels on the ...

Tips for avoiding Bootstrap collapse overflow within a container that has overflow-y-scroll

I'm currently facing an issue with a container that has the overflow-y-scroll CSS property. Inside this container, there's a Bootstrap collapse button that expands to show more content when clicked. The problem arises when the expanded content ov ...

Setting the Minimum Width of Floating Columns in HTML and CSS

Can anyone provide some assistance? I am currently using a design that I want to modify so that the columns do not compress or shrink below a certain size. I have attempted to use "min-width" without success. Any help would be greatly appreciated. Thank y ...

Annoying AngularJS Scrolling Problem

I am facing an issue with a Container that loads multiple views <md-content flex id="content"> <div ng-view></div> </md-content> One of the loaded views has the following structure: <div layout="column" id="selection-whit ...

A step-by-step guide on using Jquery to fade out a single button

My array of options is laid out in a row of buttons: <div class="console_row1"> <button class="button">TOFU</button> <button class="button">BEANS</button> <button class="button">RIC ...

Using Angular's Hostbinding feature to toggle a button and change the background color of the

How can I change the background color of a page and all child components when a toggle button is clicked? Can this be accomplished using HostBinding in Angular? <div class="mainbody" [class.bgnight]="haveClass"> <button (click) ...

What happens to the page layout when a user adjusts the window size?

Is there a way to ensure that a div remains at 40% of the full screen width, regardless of window size changes? I am looking for a JavaScript or JQuery code that can lock the setting of the div to always be 40% of the full screen size. <div style="wi ...

Position the Anchor element at the center with the flex attribute inside the li element

How can I center text anchor inside an li element using bootstrap (without CSS if possible)? .nav-lt-tab .nav-item .nav-link { background-color: transparent; border-top: 3px solid #e0e0e0; } <html> <head> <link rel="stylesheet" h ...

steps for centering an image on an ionic page

Is there a way to center an image (logo) both horizontally and vertically on the page? <ion-view hide-nav-bar="true"> <ion-content class="backgound-red "> <section class = "home-container"> <div class="row icon-row"> ...

How can I ensure the height of the Bootstrap vertical navigation menu appears consistent on every page

I'm struggling to get the vertical navigation menu to reach all the way down to the footer of the page. I've tried adjusting it, but the closest I came was setting a specific height for the .navbar, which isn't ideal because I want it to be ...

Enhance Ruby JSON by including a trailing comma and bracket at the end

Could someone assist me in adding commas between my hashes and enclosing them in square brackets? I would greatly appreciate it! Below is the code I am working with: namespace :fieldfacts do desc "Export Topics" task :export_topics => :environment ...

"Despite setting remote: true on a basic form, no AJAX request is being initiated and the result is a

Although there are numerous discussions on this particular issue, most of them are outdated and do not involve ActionCable. So, here's the challenge at hand: I'm creating a chat feature with ActionCable and successfully broadcasting messages. Th ...

Aligning Cards using Bulma Styles

Currently in the process of developing a Pomodoro Timer application and utilizing Bulma as my CSS Framework. I am really enjoying working with it thus far, although still getting the hang of Flexbox. I am seeking advice on the best approach for this projec ...

Strangely Bizarre CSS Quirk

At this website, there seems to be an issue with how the footer displays on Internet Explorer and certain older versions of Firefox. However, it appears perfectly fine on Firefox 3.6.13. Any suggestions on what could be causing this discrepancy? ...