Utilizing CSS for creating dynamic columns within a Bootstrap row

Is there a way to dynamically change the background color of each section in a bootstrap row based on percentages passed through? For example, if I pass in percentages of 30, 40, 20, and 10, the divs should appear in green, red, yellow, and purple respectively.

The percentages will be changing dynamically. How can this be achieved?

The code required is quite simple


<div class="row">
<div class="twenty"></div>    
<div class="forty"></div>  
<div class="ten"></div>  
<div class="thirty"></div> 
</div> 

I am using an Angular 2 component to pass the class value.

Answer №1

Assign unique identifiers to them

<div class="row">
 <div class="your_class" id="first_row"></div>
 <div class="your_class" id="second_row"></div>
</div>

Next, specify your styling preferences using CSS

#first_row {
  ... !important; /* if needed */
}

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

The background color is not extending to the edges of the row or column

After making adjustments to the layout of a specific section on my webpage by adding rows and columns, I noticed a blank strip where the background color fails to fill in. The rows within this section are contained within a div class called container-fluid ...

Is it recommended to employ @media print for a webpage dedicated exclusively to printing purposes?

Imagine a scenario where I have a specific page featuring a print button. Clicking on this button redirects me to a separate page with the same content, optimized for printing purposes. Instead of using @media print directly on the original page due to n ...

Choosing an element in JQuery based on the value of its style property

I have three divs with the same class but different styles. I need to select only the third one using JQuery. <div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-div ...

Aligning a DIV using javascript

Hey everyone, I'm encountering an issue with the JavaScript on my website. I'm struggling to center the div in order to properly display the image I click on. It seems to work fine on the second attempt, but on initial click, the div always appea ...

Switching templates based on elementRef width adjustments

I am facing an issue where I am trying to load some data in ngInit and set the width of a div equal to the received data. However, when I try to set some style options in ngAfterViewInit using ViewChild and ElementRef, my elementRef ends up being undefined ...

Displaying a specific division solely on mobile devices with jQuery

I need to implement a feature where clicking on a phone number div triggers a call. However, I only want this div to be displayed on mobile devices. To achieve this, I initially set the div to "display:none" and tried using jQuery to show it on mobile devi ...

Breaking down an HTTP request using the Angular, Express, and MongoDB stack

In order to optimize performance, I am faced with the challenge of retrieving a large number of elements from a MongoDB database and displaying them on the front-end. Fetching all elements in a single request may negatively impact performance due to the la ...

Using Angular DataTables to make an AJAX call from browser's local storage

I am exploring a method to retrieve data from local storage via an ajax call and load it into a table as a JSON object. fetchDataForTable() { this.jsonService.retrieveJson().subscribe(response => { this.dataToDisplay = response.data; }); t ...

Adding custom fonts to DOMPDF: a step-by-step guide

First, I moved the dompdf library folder to /dompdf Next, I added a /fonts folder containing Roboto-Black.ttf Then, I created an index.php file <?php // Autoloader inclusion require_once 'dompdf/autoload.inc.php'; // Namespace reference ...

Ways to conceal a grid item in Material UI framework

My goal is to hide a specific grid item for a product and smoothly slide the others in its place. Currently, I am using the display:none property but it hides the item instantly. I have already filtered the products and now I want to animate the hiding of ...

Is there a way to disable a field or div in Angular 8 based on a user's role permission, rather than just showing or hiding it with ngx-per

<div *customPermissions="['USER']"> <div><input type="text" placeholder="testing custom permission"></input></div> </div> This code snippet displays a div based on custom p ...

Why do CSS media queries stop working at exactly 5 distinct resolution sizes? This seems odd

Just completed my first JavaScript project, a 3D website using three.js. However, right before publishing, I realized that the dimensions and contents were not optimized for viewing on browsers other than 1920x1080. So, I delved into setting DevicePixelRat ...

When the canvas is in full screen mode, my div elements are hidden

Currently, I am immersed in a 360-panorama project, utilizing panolens.js and three.js. While Panolens offers fullscreen mode functionality, the problem arises when entering this mode as the canvas conceals all of my div elements. One particular div elemen ...

Steps for displaying a new event on a fullCalendar

Utilizing fullCalendar to display a list of events in the following manner: this.appointments = [{ title: "Appointment 1", date: "2020-09-06", allDay: false }, { title: "Appointment 2", date: "2020 ...

What sets [NgClass] apart from [class] in Angular JS2?

Consider a view element with the following three attributes: class="red" [class]="isGreen ? green : cyan" [ngClass]="'blue'" Does Angular merge the output of these attributes or does one override the others? If we have: [class]="getElementCla ...

Guide to dividing the screen into three horizontal sections

I am currently working on a website and trying to divide a page into three different sections: one for the title and a button, one for the content, one for the text input. . The issue I'm facing is that the divs are not filling the height and ...

Choose several checkboxes from the dropdown menu

After clicking the dropdown, I want to select multiple checkboxes instead of just one. I have tried using the prevent default method but it did not work. Beginner concept ...

Is there an improved method for toggling animations in CSS using jQuery compared to my current approach?

Looking to create a toggle effect for a dropdown box that appears and disappears when a button is clicked. var clickState = false; $("#show").on("click", function() { if (!clickState) { $(".animated").removeClass("off"); refreshElement($(".an ...

What is the most effective way to handle DOM events in Angular 8?

Looking to listen for the 'storage' event from the window in Angular 8. What is the recommended approach to achieving this in Angular? window.addEventListener('storage', () => { }); One method involves using Renderer2, but are ther ...

Strategies for managing dependent HTTP service call subscriptions with RxJs operators

In my application, I have implemented a function called fetchSeviceProviders that retrieves a list of service providers and allows me to set the logo for each provider by making a separate API call. Currently, I am using two subscriptions to achieve this f ...