What is the best way to ensure an inline HTML style takes precedence over a CSS style?

I'm trying to pass a value into an Angular Material Table in order to set the row color to black. However, it seems like my CSS stylesheet keeps overriding this setting which is meant to make the rows gray. I thought inline styling should take precedence here, but it doesn't seem to be working as expected. What could be the issue?

My expectation was that setting the row color value would take precedence:

<mat-row *matRowDef="let row; columns: displayedColumns;" [ngStyle]="{'background-color': row.color}"></mat-row>

Instead, the CSS below (which sets specific columns to blue) appears to be taking precedence:

.mat-column-paios, .mat-column-papc, .mat-column-pd, .mat-column-appfamily-pa,
    .mat-column-appfamily-pd, .mat-column-eis, .mat-column-appfamily-eis {
        background-color: #26428b;
        color: white;
        flex: 0 0 7%;
    }

Here is the HTML code snippet:

<mat-table class="lessons-table mat-elevation-z8 overflow-x-auto" [dataSource]="serverLicenseDS" matSort (matSortChange)="sortData($event)">
        <ng-container matColumnDef="paios">
            <mat-header-cell *matHeaderCellDef>PAIOS</mat-header-cell>
            <mat-cell *matCellDef="let e">{{e.paios}}</mat-cell>
        </ng-container>
        <mat-header-row *matHeaderRowDef="displayedColumns; sticky:true"></mat-header-row>
        <mat-row *matRowDef="let row; columns: displayedColumns;" [ngStyle]="{'background-color': row.color}"></mat-row>
    </mat-table>

And this is my relevant CSS:

.overflow-x-auto {
        overflow-x: auto;
    }

    .mat-column-select {
        overflow: initial;
    }

    .example-container {
        display: flex;
        flex-direction: column;
        min-width: 300px;
    }

    .example-header {
        min-height: 64px;
        padding: 8px 24px 0;
    }

    .mat-column-sumName {
        background-color: black;
        color: white;
        flex: 0 0 16%;
    }

    /* Other column styles */
    

Answer №1

To incorporate a new style into your project, you can use the following CSS code:

.highlighted-row {
    background-color: blue;
 }

Apply this class to the custom-tag within your HTML as demonstrated here:

<custom-row [ngClass]=('highlighted-row')></custom-row>

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

Create a section and a div with a set size in HTML

I'm having trouble setting the height of a div within a section to 100px. Despite my efforts, the height keeps reverting back to 'auto' and adjusts based on the content inside the div. Below is the HTML code: <section id="social" class= ...

Achieving consistent column heights in Bootstrap by aligning neighboring columns

I am striving to achieve a layout similar to this: https://i.sstatic.net/HIEB4.png However, in Bootstrap, I am currently getting this: https://i.sstatic.net/sLw1v.png My desired layout specifications are as follows: Width ratios should be in the propor ...

A helpful tip for creating line breaks within a Vue JS v-for loop using CSS

I am looking to arrange the names in alphabetical order when a list item is clicked. My tools of choice are Vue.js and Flex Grid. The list item I am working with is called ListAll, When clicking on ListAll, I want to display all the records grouped by na ...

There is a button on my website that uses a small piece of Javascript to post a tweet, but unfortunately, it is not functional on mobile devices

Check out this link to view the demonstration - http://codepen.io/illpill/pen/VbeVEq function sendTweet(message, author) { window.open('https://twitter.com/intent/tweet?hashtags=thequotemachine&text=' + encodeURIComponent('"' + m ...

Is it possible to toggle CSS classes worldwide?

One of my CSS techniques involves outlining every div in red, which is helpful for debugging alignment of elements. In my app, I have a button that currently toggles various debugging features. I'm interested in incorporating the toggling of these re ...

Switching the input to LTR changes the overall direction to LTR while maintaining the RTL placeholder

The text input is currently set to be RTL, including both the placeholder and the actual input. The settings for this were done elsewhere. My question is how can I modify it so that only the input changes to LTR, while the placeholder remains RTL. For exa ...

The type 'Event' argument cannot be assigned to the 'InfiniteScrollCustomEvent' parameter

I'm facing an issue with Ionic Angular. Here is my movies.page.html: <ion-header> <ion-toolbar color="primary"> <ion-title>Trending Movies</ion-title> </ion-toolbar> </ion-header> <ion-content ...

Is it possible to delete a <div> tag based on screen size using jQuery or JavaScript?

Hello, I was curious if it's possible to dynamically remove a specific div tag using jQuery or JavaScript when the screen reaches a certain size, for example 500px. ...

The issue with Visual Studio not properly supporting Angular development

After cloning my Angular app from one machine to another, I encountered an issue when trying to run it with debugging in Visual Studio. Instead of opening a separate command line and executing ng serve or npm start, it simply launched a web browser page on ...

Adjust the font size based on the dimensions of the container

I'm currently working on a script that dynamically sets the font-size based on the container's dimensions and the length of the text. This is what I have implemented so far. window.onload = function () { var defaultDimensions = 300; ...

Text alignment in the horizontal direction does not function as expected within the `<span>` element in Bootstrap 4

The code snippet below is what I am currently working with: <div class="card" > <div class="card-block"> <h4 class="card-title"> <span class="text-left"> ...

Utilizing RouterLink along with a button and conditional rendering in Angular

One issue I am facing is using *ngIf to navigate to a different page based on a variable. Despite having valid links, when I click on the button nothing happens. Here is the code snippet: <button mat-button > <span class=&quo ...

error with angular5 material table data source

I tried multiple solutions from Stack Overflow but none of them worked for my Angular 5 project using TypeScript. I'm attempting to replicate the "Data table with sorting, pagination, and filtering" example from here. Although there are no errors, th ...

Child component received an incorrect input value

Utilizing both the "YearComponent" and "StatPeriod" components has presented some challenges for me. Within my YearComponent, I invoke StatPeriod as follows: <app-save-stat-period [dateBegin]="dateBegin" [dateEnd]="dateEnd" byMonth bestNAverage></ ...

Leveraging the power of Angular's function within ElementRef and accessing the

Is there a way to access an Angular function using ElementRef? ngAfterViewInit() { let _self = this; this.datatable.on('m-datatable--on-layout-updated', function(e){ $(_self.elRef.nativeElement).find('.deleteFn').c ...

What could be causing the "buffer is not a function" error to occur?

As a beginner with observables, I'm currently working on creating an observable clickstream to avoid capturing the 2 click events that happen during a double-click. However, I keep encountering this error message:- Error: Unhandled Promise rejection ...

Using the scrollIntoView method on an element with a height of 0 within an Angular 2+ application

I am currently working with the following HTML code snippet: <div class="row-20 st-margin" *ngIf="role == 'Administrator'" id="hr-data"> <div class="col-md-12"></div> </div> After ...

Modify the color of a table cell date using PHP

I need to change the color of my td's client_birth_date based on the current date. For instance, if today is the client's birthday, I want the font color of this td to turn red. Here is a snippet of my HTML code: <?php foreach ($rows as $row) ...

Modify css with php instead of using FTP

As I work on constructing a website, I wonder how WordPress allows its admin users to edit CSS styles through the website instead of accessing the css file directly via FTP. How exactly does WordPress load the CSS file? My assumption is that it somehow re ...

Tips for customizing the appearance of ToggleButton in material-ui

Currently, I'm working on customizing the ToggleButton in order to change the default color when it is selected. However, my attempts have been fruitless so far. const customizeStyles = makeStyles((theme) => ({ toggleButtonSelected: { &q ...