如何在点击时突出显示 bootstrap 卡片?

How to highlight a bootstrap card onClick?

我是 bootstrap 的新手。我们有一些卡片,我们想在点击时突出显示一张卡片。卡片是这样的-

<div class="container">
    <div class="row">
        <div class="card">
            <div class="card-header">Header</div>
            <div class="card-body text-dark">
                <h5 class="card-title">title</h5>
                <p class="card-text">Quick text</p>
            </div>
        </div>

        <div class="card">
            <div class="card-header">Header</div>
            <div class="card-body text-dark">
                <h5 class="card-title">title</h5>
                <p class="card-text">Quick text</p>
            </div>
        </div>
        <div class="card">
            <div class="card-header">Header</div>
            <div class="card-body text-dark">
                <h5 class="card-title">title</h5>
                <p class="card-text">Quick text</p>
            </div>
        </div>
    </div>
</div>

我们想在点击时突出显示一张卡片。怎么做 ?

这里是stackblitzlink.

请指导/帮助。

app.component.css:

.highlight {
  background-color: yellow;
}

app.component.html:

<div class="container">
    <div class="row">
        <div class="card" [ngClass]="{'highlight':checkIfCardIsClicked(1)}"
    (click)="setcurrentlyClickedCardIndex(1)">
            <div class="card-header">Header</div>
            <div class="card-body text-dark" >
                <h5 class="card-title">title</h5>
                <p class="card-text">Quick text</p>
            </div>
        </div>

        <div class="card" [ngClass]="{'highlight':checkIfCardIsClicked(2)}" 
    (click)="setcurrentlyClickedCardIndex(2)">
            <div class="card-header">Header</div>
            <div class="card-body text-dark">
                <h5 class="card-title">title</h5>
                <p class="card-text">Quick text</p>
            </div>
        </div>
        <div class="card" [ngClass]="{'highlight':checkIfCardIsClicked(3)}"
    (click)="setcurrentlyClickedCardIndex(3)">
            <div class="card-header">Header</div>
            <div class="card-body text-dark">
                <h5 class="card-title">title</h5>
                <p class="card-text">Quick text</p>
            </div>
        </div>

    </div>
</div>

app.component.ts:

import { Component } from "@angular/core";

@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent {
  name = "Angular";

  public currentlyClickedCardIndex: number = 0;

  public setcurrentlyClickedCardIndex(cardIndex: number): void {
    this.currentlyClickedCardIndex = cardIndex;
  }

  public checkIfCardIsClicked(cardIndex: number): boolean {
    return cardIndex === this.currentlyClickedCardIndex;
  }
}

我的解决方案会记住上次单击的卡片的索引以仅突出显示该卡片。 我