The _rfs.scss width rule in Angular-Bootstrap-NgBootstrap is overriding the column width of the col-rules

The Dilemma

I am currently working on an Angular project that incorporates Bootstrap and ng-bootstrap. My intention is to utilize the grid system within this project, but I encountered some bugs along the way.

When trying to render the following HTML/TS code (with an empty SCSS file)

<div class="container-fluid">
  <div class="row">
    <ng-container *ngFor="let entry of entries">
      <span 
        class="col-md-6"
        style="height: 3rem; border: 2px solid black;"
      >
        Text
      </span>
    </ng-container>
  </div>
</div>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  entries = Array(8).fill(undefined);
}

The output appears as follows: https://i.stack.imgur.com/37l45.png

I was expecting to see 2 columns of entries, similar to what is shown in the second screenshot below.

Although the styling of the col-md-6 class is correctly applied, there seems to be an issue where the width settings are being overridden by certain rules defined in _rfs.scss, a feature within Bootstrap.

Findings

To investigate further, I set up a new project with Bootstrap and ng-bootstrap installed, where the same HTML code worked without any problems. This indicates the issue is specific to my original project.

https://i.stack.imgur.com/zIjUA.png

Here's what I have uncovered so far:

  • The HTML structure and CSS classes are correct, as they render properly in a fresh project.
  • The issue does not seem to stem from the Bootstrap.scss imports, which follow the standard format of
    @import '/node_modules/bootstrap/scss/bootstrap.scss';
  • Copying over all relevant SCSS files to the new project did not result in any rendering issues.
  • Installing ng-bootstrap did not cause any complications in the fresh project either.
  • The package.json dependencies and angular.json assets/styles also do not seem to be related to the problem.
  • The inconsistency appears to be component-specific, affecting how the HTML is processed in each respective project.

With these observations in mind, I have a couple of questions:

  • Why are the _rfs.scss rules impacting the rows only in my original project, but not in the fresh one?
  • How can I resolve this conflicting behavior?

Related Issues

There is a similar question posted about this matter here.

However, the proposed solution in that thread did not address the underlying problem effectively. The overriding of the width property by _rfs.scss is indeed causing the initial discrepancy, though the root cause might involve the presence of _rfs.scss itself, which remains uncertain.

It should be noted that assigning just "col-md-6" is adequate to achieve the desired column layout based on screen size, as demonstrated in Bootstrap documentation.

Due to insufficient details provided in the previous question for troubleshooting purposes, it seemed necessary to create a new inquiry.

Troubleshooting Resources

If applicable, here is my styles.scss content:
@import './custom_bootstrap.scss';
@import '/node_modules/bootstrap/scss/bootstrap.scss'; //Must be imported after custom_bootstrap so that values from custom_bootstrap are available for overriding
@import './variables.scss';

html{
    font-size: 16px;
}

body{
    font-family: "Source Sans Pro", sans-serif;
    overflow-x: hidden;
}

.highlight{
    background-color: var(--highlight-gray);
}

.hover-highlight{
    transition: 0.2s background-color;
}

.pointer{
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
    .hover-highlight:hover{
        background-color: var(--highlight-gray);
    }
}

h1, h2, h3, h4, h5, h6 {
    color: #ffffff;
    font-weight: bold!important;
    line-height: 1.5;
    margin: 0 0 1rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}


h1{
    letter-spacing: 0.5rem!important;
    font-size: 2.25rem!important;
    line-height: 1.3!important;
}

h2{
    letter-spacing: 0.2rem!important;
    font-size: 1.5rem!important;
}

blockquote{
    border-left: solid 4px var(--bs-white);
    font-style: italic;
    margin: var(--spacer-0);
    padding: var(--spacer-2) var(--spacer-0) var(--spacer-1) var(--spacer-4);
}

@import './custom_ngbootstrap.scss';
@import './global_class_modifications.scss';
@import './custom_leaflet.scss';

Answer №1

My scss file for that particular component wasn't actually as empty as I originally mentioned. Despite this, I didn't notice any styling being applied from it, so I didn't think it was relevant. The issue stemmed from the fact that my screens.scss file was imported there and the contents of screens.scss appeared like this:

@import '/node_modules/bootstrap/scss/bootstrap.scss'; // <-- Problematic way of importing bootstrap
...

The problematic aspect lies in the bootstrap import. More specifically, the specific method of how the import is done. For some reason, having this additional bootstrap import (in addition to the one in styles.scss) causes complications with RFS.

This can easily be resolved by altering the way in which you import bootstrap. The following method worked seamlessly:

@import 'bootstrap/scss/bootstrap';
....

However, I have since removed screens.scss and opted to use the built-in Bootstrap tools for media queries, which could be valuable to mention. Nevertheless, an import of Bootstrap similar to the above is still necessary.

It might be beneficial to note that transitioning to @use instead would be advisable, considering that the SASS community is moving towards phasing out @import.

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

When the route changes, routerCanReuse and routerOnReuse are not invoked

I am currently exploring the functionalities of Angular2's Router, specifically focusing on OnReuse and CanReuse. I have followed the documentation provided here, but I seem to be encountering difficulties in getting the methods to trigger when the ro ...

Beginner: Add "shared" module elements to app.module and include them in app.component.html as part of the app's layout

I am trying to incorporate three components from a "shared" module into app.component.html. Here is my current setup: <header></header> <div class="main-wrapper"> <div class="bg-trick"></div> &l ...

Tips for validating the request body prior to sending in Angular unit testing

I'm experiencing some difficulties creating a unit test. Despite reading numerous articles, none have proven to be helpful in simplifying the process. The specific function I need to test returns an Observable. My main objective is to ensure that myB ...

Error loading the website on Firefox

The background image in my CSS code is not displaying in the browser. I am currently working in the CodeIgniter framework and using Firefox. #star ul.star { list-style:none; margin:0; padding: 0; width:85px; height:20px; left: 10px; top:4px; pos ...

Error: Unable to access the 'visitStatement' property of an undefined object within Angular 2

Help! I encountered an error in my angular2 application. The error message says: TypeError: Cannot read property ‘visitStatement’ of undefined ...

What are the steps to create a toggle navbar with Bootstrap?

I am facing an issue with the Navbar Toggle in Bootstrap 5.2. The hamburger button displays correctly on a small screen, but when I click on it, the navigation items do not appear. Any suggestions on how to fix this? <body> <nav class="navba ...

My page is experiencing delays due to setInterval

Currently, I am delving into the world of Chrome Extension development and am faced with a roadblock in replacing elements on a live chat page. While most of my tasks are running smoothly, the one thing causing issues is the setInterval option that trigger ...

Adjustable Bootstrap Progress Bar - Modify element width on the fly

I have encountered an issue with my progress bars on the webpage. The static HTML version works perfectly fine, but the dynamically created one using jQuery seems to be instantly at 100% without any delay in progression. To illustrate the problem better, ...

What is the updated technique for creating a full-width HTML section in 2023?

In most web designs, the content is typically "contained" to be centered and limited by a maximum width: <!DOCTYPE html> <html> <body> <div id="container" style="width: 1000px; margin: 0 auto;"> ...

When scrolling on an IOS mobile device, the .on(click) event is triggered for fixed position elements

Whenever I click on an li element or menu, a function is triggered that moves the nav container to the left by the width of the window. However, on my iPhone, after I click to slide the container off the screen, the event gets triggered repeatedly every ti ...

What is the best method to center a div on the screen?

Is there a way to have a div open in the center of the screen? ...

What is the method used to calculate the heights of flex items when the flex-direction property is set to column?

I'm currently grappling with the concept of flexbox layout and have been exploring the flex-direction: column option. HTML <div class="container"> <div class="item"> Lorem ipsum dolor sit amet consectetur a ...

Conceal any elements that have a class containing specific text

In my HTML file, I have multiple <span> elements with the class of temp_val that include a 1 value which I need to hide. These elements are placed throughout the document. Below is an excerpt from my HTML code: <div class="row" style="float: lef ...

Tips on resizing images in CSS with accompanying text to prevent overlap

In my school project, I am using cloud9. When utilizing the live preview in a small window pane, my images appear correctly sized. However, upon maximizing my screen browser, the images stack on top of each other and their dimensions increase. My ideal l ...

Utilizing inline styles with the asset pipeline feature in Rails

<%= link_to root_path do %> <div class=""> <div style="background-image:<%= image_tag " image1.png "%>"> </div> <div> <h2>Title</h2> <p>Paragraph</p> </div& ...

"Utilizing ng2 dragula allows for the seamless addition of new data to an element after it has been dropped, based on the

My experience with the ng2 Dragula library revealed some intriguing aspects. I noticed that when dragging an element from one container to another, the element would expand to showcase additional data features such as Droplists, HTML input forms, and more ...

Looking to showcase website HTML code by simply clicking on a banner image?

I am looking to implement a feature where banner HTML code is displayed in a popup on website when the banner is clicked. For instance, an example of a banner could be: <img src="https://myweb.com/images/banners/1.gif"> Upon clicking the banner im ...

Problematic: BS4 Cards cannot be accommodated within the parent div.Improved: The

Within a dynamic-height parent div, I have two cards stacked on top of each other. However, the issue arises when these two cards do not completely fit inside the parent div. The problem likely stems from the table within the lower card, which is not respo ...

What is the best way to toggle text visibility with a button click and what alternative method can be used if getElement does not work?

After successfully completing the HTML and CSS part, I hit a roadblock with JavaScript. I'm struggling to figure out how to create a button that can toggle the visibility of text when clicked. An error message keeps popping up in the console stating ...

Why does LESS keep prompting me with missing elements?

I am currently working on my first project using Less and have been following a tutorial closely. However, when I try to compile with lessc, I encounter the following error: ParseError: Unrecognised input. Possibly missing something in C:\Path\t ...