Divs are not being organized into rows correctly due to issues with Bootstrap styling

I have implemented Bootstrap in my Angular application. The stylesheet link is included in my Index.html file as follows:

<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.css">

In addition to that, I have listed Bootstrap as a dependency in my Package.json file:

"private": true,
  "dependencies": {
    "@angular/animations": "^9.1.2",
    "@angular/cdk": "^9.2.1",
    "@angular/common": "~9.1.2",
    "@angular/compiler": "~9.1.2",
    "@angular/core": "~9.1.2",
    "@angular/forms": "~9.1.2",
    "@angular/material": "^9.2.1",
    "@angular/platform-browser": "~9.1.2",
    "@angular/platform-browser-dynamic": "~9.1.2",
    "@angular/router": "~9.1.2",
    "bootstrap": "^4.4.1",
    "rxjs": "~6.5.5",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },

However, despite having the necessary setup, the columns are not aligning properly on the same row as expected when utilizing the following code snippet within my application:

<div class="container">
  <div class="row">
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
  </div>
</div>

I have attached a screenshot showing the current layout of my application for reference:

Any assistance in resolving this issue would be highly appreciated.

Answer №1

To properly integrate Bootstrap into your project, make sure to use

@import '~bootstrap/dist/css/bootstrap.min.css';
in your styles.css file instead of a link tag in the index.html file (IMPORTANT).

Additionally, in the styles section of your angular.json file, specify the location of your bootstrap.css file:

"styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
]

Ensure that you have Bootstrap 4 installed to utilize the col-sm class effectively.

Here's an example snippet from my angular.json in the project:

Answer №2

Kindly update your class "col-sm" to "col-sm-4".
You should specify the number of columns you desire (using tags with the correct .col-- classes)

Answer №3

Start by installing Bootstrap 4 and jQuery using npm

$ npm install --save bootstrap jquery

Next, go to the angular.json file and include the paths for Bootstrap CSS and JS files as well as jQuery in the styles and scripts arrays under the build target.

 "architect": {
  "build": {
    [...], 
    "styles": [
      "src/styles.css", 
        "node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],
      "scripts": [
        "node_modules/jquery/dist/jquery.min.js",
        "node_modules/bootstrap/dist/js/bootstrap.min.js"
      ]
    },

For three rows, use <div class="col-sm-4"> instead of <div class="col-sm">

To create custom rows, check out this 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

Hosting static files in .NET Core 3.1

I am encountering an issue with my app built on .Net Core 3.1 and Angular 10. Within my Startup.cs file, I have the following code snippet: app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Path. ...

Explore the refined search capabilities within the ng-select dropdown component in Angular

I am currently utilizing the ng-select library for a list of cities, such as: cities = [ {id: 1, name: 'MA, Boston'}, {id: 2, name: 'FL, Miami'}, {id: 3, name: 'NY, New York', disabled: true}, ...

Utilizing Angular Forms for dynamic string validation with the *ngIf directive

I have a challenge where I need to hide forms in a list if they are empty. These forms contain string values. I attempted to use *ngIf but unfortunately, it did not work as expected and empty fields are still visible in the list. How can I address this iss ...

The React Nested Loop Query: Maximizing Efficiency in Data

Learning React has been a challenge for me, especially when comparing it to XML/XPath. In this scenario, I have two arrays simplified with basic string properties... customerList: Customer[] export class Customer { id: string = ""; firstnam ...

Sharing information among components in Angular

This is the structure of my page: app.component.html <app-header></app-header> <router-outlet></router-outlet> <app-footer></app-footer> The data loading process occurs in the app.component.ts file via a shared ser ...

Is there a way to fetch a particular object from Firebase database based on its value using AngularFire2?

Here is the database I am working with: firebase database I am trying to retrieve a dish that has its 'featured' attribute set to true (dish.feature = true). Is it possible to do this directly from the database, or do I have to retrieve all di ...

The chosen Angular material pre-built theme of indigo-pink does not seem to be applied properly

Within my styles.scss @import '~@angular/material/prebuilt-themes/indigo-pink.css'; I have also attempted this in my index.html <link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet" /> Finally, I m ...

The exit code 1 was triggered in the npm-lifecycleindex.js file at line 285,

0 silly lifecycle <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bac9ced5c8d194c9cadbfa8b948a948a">[email protected]</a>~build.prod: Args: [ '/d /s /c', 10 silly lifecycle 'gulp build.prod --color --en ...

Angular2 - HTML not displaying the response

I am currently mastering angularjs2. In my latest project, I attempted to fetch data from an API and received a response successfully. However, I encountered an issue where the response is not rendering in homepage.component.html as expected. I am unsure o ...

the behavior subject remains static and does not update

Working on setting my language in the BehaviorSubject with a default value using a LanguageService. The service structure is as follows import {Injectable} from '@angular/core'; import * as globals from '../../../environments/globals'; ...

Creating test cases for a service that relies on a Repository<Entity> to consume another service

Having trouble creating tests for an auth.service that seems pretty straightforward from the title. However, every time I run the tests, I encounter this error: TypeError: Converting circular structure to JSON --> starting at object with cons ...

Comparing strings with data in objects using Angular

all. I have a query. What is the optimal method for comparing data? For instance, if you have a constant response = 225235743; And I aim to locate and exhibit all data in an object with the same ID as the one in this response. This needs to be resolved ...

Display Module within Component using Angular 5

In the application I'm working on, I want to incorporate a variety of progress-loader-animations such as spinners or bars. To achieve this, I've developed a module with a component. Now, I'm trying to figure out how to display the module&ap ...

Can we find a superior method?

I am currently using a stateful service to retrieve questions. The service checks if the questions exist in the local state, and if they do, it returns them. Otherwise, it makes an HTTP call to the API to fetch and store the questions. The service method ...

Can the floating side of a div be switched after resizing?

Let's say I have two divs set up in the following configuration: |------------------------------| | div1 ------------------ div2 | |------------------------------| .div1{ float:left; } .div2{ float:right; } From my understanding, they w ...

Encountering a CORS problem following a successful API request within an ABP application

Access to XMLHttpRequest at 'serversiteurl//api/services/app/QklyProcessEngine/CallProcess' from origin 'clientsiteurl' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resou ...

Exploring the similarities between using jQuery AJAX post and Angular

In my current project, I have a legacy application that relies on jQuery and unfortunately cannot incorporate Angular at this time. For one specific task, I need to make an AJAX POST request to consume a web service using jQuery. Interestingly, the same ...

Angular 2 - Alert: (SystemJS) Stack size limit exceeded(…)

Need some help here: Error: (SystemJS) Maximum call stack size exceeded(…) I have a situation where I am facing an error related to the maximum call stack size being exceeded. It seems to be linked to the import of another module in my component. Let&a ...

What steps can be taken to ensure a successful request to a Node.js server when previewing an Angular app on a separate device within the same network?

My desktop computer hosts the Angular front-end on port 4200 and the Express.js back-end on port 4000. When I try to access the Angular app from my mobile Android phone using 192.168.1.X:4200, the app loads but doesn't display any data from the Expres ...

Angular 2 Encounter Error When Trying to Access Undefined Property in a Function

Element: import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Component({ selector: 'app-ore-table', templateUrl: './ore-table.component.html', styleUrls: [&a ...