如何自定义ngx-datatable行的CSS

huangapple go评论71阅读模式
英文:

How to customize ngx-datatable css for rows

问题

我尝试为ngx-datatable元素应用一些CSS,如下所示。

.datatable-body-row:hover {
  background-color: #3387b5;
}

没有任何变化,结果仍然相同。CSS保持默认设置。
当我将鼠标悬停在特定行上时,颜色仍然相同。
我如何自定义它?谢谢。

供参考,整体的HTML结构如下。

<ngx-datatable>
  <!-- 行包含在这些列中,但这些列包含标题 -->
  <ngx-datatable-column>
    
    <ng-template ngx-datatable-header-template>
      <label class="datatable-checkbox">
        <input />
      </label>
    </ng-template>

    <ng-template ngx-datatable-cell-template >
      <label class="datatable-checkbox">
        <input type="checkbox" />
      </label>
    </ng-template>
  </ngx-datatable-column>

  <ngx-datatable-column *ngFor="let column of columns; let i = index">
  </ngx-datatable-column>

</ngx-datatable>
英文:

I try to apply some css for the ngx-datatable element like this.

.datatable-body-row:hover {
  background-color: #3387b5;
}

Nothing changed, result are the same. The css remains default setting.
The color is still the same when I hover my mouse to the specific row.
How can I customize it? Thankyou.

For reference the over all HTML structure are like this.

&lt;ngx-datatable &gt;
  &lt;!-- row are included in these column, but these column includes header--&gt;
  &lt;ngx-datatable-column &gt;
	
    &lt;ng-template ngx-datatable-header-template&gt;
      &lt;label class=&quot;datatable-checkbox&quot;&gt;
        &lt;input /&gt;
      &lt;/label&gt;
    &lt;/ng-template&gt;

    &lt;ng-template ngx-datatable-cell-template &gt;
      &lt;label class=&quot;datatable-checkbox&quot;&gt;
        &lt;input type=&quot;checkbox&quot; /&gt;
      &lt;/label&gt;
    &lt;/ng-template&gt;
  &lt;/ngx-datatable-column&gt;

  &lt;ngx-datatable-column *ngFor=&quot;let column of columns; let i = index&quot; &gt;
  &lt;/ngx-datatable-column&gt;

&lt;/ngx-datatable&gt;

答案1

得分: 1

可能降低CSS优先级

您可以使用这种方法或其他方式提高优先级:https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

.datatable-body-row:hover,
.datatable-body-row:hover .datatable-row-group {
  background-color: #3387b5 !important;
}
英文:

Probably lower CSS Priority

you can use this or raise Priority other way https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

.datatable-body-row:hover, 
.datatable-body-row:hover .datatable-row-group {
  background-color: #3387b5 !important;
}

huangapple
  • 本文由 发表于 2023年1月9日 17:44:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定