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

Ways to format table using flex-wrap sans the use of flexbox

My HTML and CSS structure is as follows: .item { background: white; padding: 5px; display: inline-block; text-align: center; } .item > div { background: yellow; width: 60px; height: 60px; border-radius: 50%; display: table-cell; ...

The reason behind encountering the "UNMET PEER DEPENDENCY" error within Angular 2

Is there a way to properly set up angular2-flash-messages in my angular-src directory instead of the root? I attempted to use npm install angular2-flash-messages, but encountered the following error: ├── UNMET PEER DEPENDENCY @angular/<a href="/c ...

Can CSS be used to consistently position content in a specific manner?

I previously inquired about a similar issue and received an excellent solution. Here is my jsbin http://jsbin.com/nuwagibayo/1/edit?html,css,output where I encountered the following scenario: The positioning of 12.50 seems slightly awkward in its current ...

How to fix the issue of the mobile Chrome bar occupying part of the screen height in CSS

I am encountering a well-known issue with my collapsible scrollable bar implemented in Bootstrap. The problem occurs when scrolling on mobile devices, as the search bar takes up space from the sidebar's 100% height, causing the scrollbar to not reach ...

tips for positioning images and text in the center using css classes

Here's what I currently have: http://jsfiddle.net/nCs88/ Here's my goal: As a beginner, I am struggling to center the button images with the text. Any help would be greatly appreciated as this has been frustrating me for hours. ...

Retrieving routing information from directives within angular2

const APP_ROUTES: RouterConfig = [ { path: 'app/home', component: HomeComponent, data: { name: 'Home' } } ] Assuming the route configuration is set as displayed above, how can one ...

Using Bootstrap columns within a PHP while loop

Encountering an issue and the code in question is shown below: <div class="col-md-4 text-center animate-box"> <a href="work-single.html" class="work" style="background-image: url(images/portfolio-2.jpg);"> ...

Troubleshooting flow problems in flexbox container for

https://i.stack.imgur.com/ZpVaH.png I have implemented a flexbox-based page layout. The layout consists of two sidebars on the left and right sides, with fixed widths, and a central content panel that dynamically adjusts to fill the remaining space. Howe ...

Replicate the ctrl+/- function through coding

While browsing with your browser, you have the ability to adjust the font size by using CTRL + + or CTRL + -. Is there a way to replicate this functionality through code, such as with JavaScript? I am looking to add buttons on my website that allow users ...

Currently, I am compiling a list of tasks that need to be completed, but I am encountering a dilemma that is proving difficult to resolve

Recently delved into the world of Javascript and encountered a roadblock that I can't seem to overcome. Here's the snippet of code causing me trouble: add = document.getElementById("add"); add.addEventListener("click", () => { console.log("Ple ...

In JavaFX, when adjusting the transparency of a popup window, only the brightness changes while the solid color remains unchanged, effectively concealing

Is it possible to have a transparent popup window (errorDialog.fxml) on top of the main window (mainWindow.fxml) with 50% opacity while still showing the content of the main window underneath? My attempts at setting the background color of the overlay insi ...

Hover your mouse over the menu to activate a timeout feature

Having an issue with my multi-level menu - when I hover over a main menu item, the sub-menu items are supposed to display. However, if I move the mouse too quickly from the main item to the sub-item and it goes off the path, the sub-menu disappears and I h ...

ServiceWorker has responded with a 503 OK status code

Recently, I implemented @angular/service-worker to create a SW for my angular4 web application. However, I encountered an issue after updating the ngsw-manifest.json file to handle dynamic requests from the server - now, whenever I go offline (after initia ...

Revamp your Redux Form with a fresh new 'Field' label style

Is there a way to style the label of a Redux Form field? The Redux Form API does not provide information on how to apply styles to the label. Despite applying the classes.formField class, the label itself remains unstyled. Could this be an issue with inhe ...

Is there a way to configure my dropdown menu so that only one dropdown can be open at a time and it remains open when clicking on a <li> item?

I've been working on developing a dropdown menu that appears when clicked, rather than hovered over. I've managed to implement this functionality using JavaScript, and overall, it's working quite well. Currently, the menu shows or hides whe ...

Techniques for adjusting the dimensions of a select dropdown using CSS

Is there a way to control the height of a select dropdown list without changing the view using the size property? ...

PrimeNG Default DataTable - Customize Column Visibility

My datatable currently has 11 columns, and I am utilizing the toggleable columns feature. However, I want to display only 4 selected columns initially out of the 11 options available. I have researched various possibilities using the MultiSelect component, ...

Is there a way to trigger a function upon the loading of a template in Angular 2?

I'm a newcomer to angular2 and I need to trigger a function when a template loads or initializes. I have experience with achieving this in angular1.x, but I'm struggling to figure out how to do it in angular-2. Here's how I approached it in ...

CSS - setting all child elements to the height of the tallest child element

Is there a way to ensure that both fieldsets have the same height as the tallest one? See the code snippet below or visit this link for reference: http://jsfiddle.net/zpcXQ/2/ <div id="parent"> <form> <fieldset id="left"> ...

Adjusting the selection in the Dropdown Box

I've been attempting to assign a value to the select box as shown below: <dx-select-box [items]="reportingProject" id="ReportingProj" [text]="reportingProject" [readOnly]="true" > ...