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:

https://i.sstatic.net/szXFq.png

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:

https://i.sstatic.net/nljTr.png

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

Ensure that the Bootstrap image element maintains its full height without resizing

While working on my Angular application, I encountered an issue with designing a side list-group of recent blogs using Bootstrap 4. When the aspect ratio is changed to mobile view, the images resize and become smaller to fit into the div as the title lengt ...

make sure the <option> tags fit seamlessly inside a Bootstrap card

I'm currently working on a project using Angular in combination with Bootstrap 4.0. My goal is to integrate <select>, <option>, and <optgroup> elements within a card. Below is the code snippet from the component.html file: <div ...

Error: No default Firebase App named '[DEFAULT]' exists. Please remember to call Firebase App.initializeApp() to create the app (app/no-app). This issue is located at the app

Currently, I am in the process of learning how to integrate Firebase Functions into an Ionic + Angular project. My goal is to develop a custom function that retrieves all games from a collection and returns an array sorted by the "count" attribute. Initia ...

Looking to start using WebDriverIO and Typescript with the WDIO wizard? Here's how to get it

I'm in the process of setting up a WebdriverIO project using TypeScript and Cucumber. I followed the steps provided by the wizard, which was pretty straightforward. I opted for Cucumber, TypeScript, and the page object model. This setup created a tes ...

The AngularJS 2 application reports that the this.router object has not been defined

My function to sign up a user and redirect them to the main page is implemented like this: onSubmit(){ this.userService.createUser(this.user).subscribe(function (response) { alert('Registration successful'); localStor ...

Running Angular 2 in Visual Studio 2012: A Comprehensive Guide

I am facing an issue trying to work with angular2 in Visual Studio 2012. I attempted following the instructions provided at https://www.codeproject.com/Tips/1026938/AngularJS-Getting-Started-with-Visual-Studio, but encountered problems at step 3. When usi ...

When utilizing a 'Token' in the provider() aliasing within Angular 2, the Typescript compiler may display an error message stating 'Unresolved variable or type'. This issue can arise when defining

When working with Typscript, I've encountered an issue where it can't handle a 'Token' in the context of an Angular2 provide() aliasing function. I'm unsure if there's a specific setting in the typescript compiler to address t ...

Unable to use console log in shorthand arrow function while working with Typescript

When debugging an arrow function in JavaScript, you can write it like this: const sum = (a, b) => console.log(a, b) || a + b; This code will first log a and b to the console and then return the actual result of the function. However, when using TypeSc ...

Issue with default behavior of infinite scroll in Angular 4

I'm currently working on incorporating infinite scroll into my Angular 4 application. I've carefully followed all the guidelines provided on https://www.npmjs.com/package/ngx-infinite-scroll According to the documentation: By default, the dir ...

Disable all typings within a specified namespace for a specific file

I need to disable typechecking for a specific namespace called MyNamespace in a Typescript file. Is there a way to achieve this without affecting other files? ...

After calling sequelize.addModels, a Typescript simple application abruptly halts without providing any error messages

My experience with Typescript is relatively new, and I am completely unfamiliar with Sequelize. Currently, I have only made changes to the postgres config in the .config/config file to add the dev db configuration: export const config = { "dev" ...

Signature of the method relies on the method call made earlier

I am currently tasked with implementing a value transformation process that involves multiple steps. To ensure reusability of these steps, a proposed architecture allows for passing steps to the transformation function. For example, transforming a long str ...

Adjust the size of every card in a row when one card is resized

At the top of the page, I have four cards that are visible. Each card's height adjusts based on its content and will resize when the window size is changed. My goal is to ensure that all cards in the same row have equal heights. To see a demo, visit: ...

Tips for arranging datasets in React Chart.js 2 to create stacked bar charts

Currently, I am facing an issue with sorting the datasets displayed in each stacked bar chart in descending order as they are showing up randomly. Here is the snippet of my code: import React from 'react'; import { Chart as ChartJS, CategoryS ...

The json-server-auth feature is failing to function properly upon initialization

I recently attempted to use json-server-auth by installing it via npm, but encountered a problem when trying to start it. The error message I received is as follows: json-server-auth : The term 'json-server-auth' is not recognized as the name ...

No test coverage report is being generated for Angular 9 in Istanbul due to its emptiness

When generating a report, I am encountering an issue where the files are listed but the percentages are not being filled in. Any insights on what might be causing this problem? Error message: An error occurred in Handlebars: Access has been denied to res ...

Adjusting Image Sizes in React using Material-UI: A Guide to Automatically Resizing Images for Various Screen Dimensions

Having trouble making images within my React project responsive across different screen sizes. Using Material-UI, I currently set the maxWidth property with a percentage value which doesn't give me the desired outcome. Seeking advice on a more dynamic ...

Is array.length access cached by NodeJS?

Lately, I've been pondering whether accessing the array.length getter is cached by NodeJS. I've searched for conclusive answers about JS interpretation in browsers, but since I am working on apps in Typescript, that information does not directly ...

Implementing a Dynamic Component within ngx-datatable's row-detail feature

I'm currently working on a project where I need to implement a reusable datatable using ngx-datatable. One of the requirements is to have dynamic components rendered inside the row details. The way it's set up is that the parent module passes a c ...

The hyperlink tag doesn't respond to clicks in Safari, yet functions properly in all other web browsers

I'm encountering an issue with my header drop-down menu in Safari—it works perfectly in Chrome, but when I try to open the drop-down menu in Safari, it's unresponsive. Clicking on it does nothing, preventing me from accessing other drop-downs. ...