【问题标题】:Apply style only to <select> tag excluding <option> in HTML仅将样式应用于 <select> 标记,不包括 HTML 中的 <option>
【发布时间】:2020-03-18 19:29:42
【问题描述】:

我只想将样式应用于父 &lt;select&gt; 标签,不包括其 &lt;option&gt; 子标签。

请看下面的代码: I want that whenever the first option is selected, my style 'highlight' should to applied to &lt;select&gt;.其他&lt;option&gt; 标签应该不受影响。

我想内联而不是使用组件级 css。 这是由于一些设计/编码准则的限制,因为所有样式都是从预定义的主样式表中获取的,并且很少添加新样式。

  <select [ngClass]="{ 'highlight': selectedUser === undefined }" [(ngModel)]="selectedUser">
    <option [ngValue]="undefined">
      Select User
    </option>
    <option *ngFor="let user of users" [value]="user">
      {{ user.name }}
    </option>
  </select>

【问题讨论】:

    标签: css angular stylesheet


    【解决方案1】:

    如果您使用的是预定义的全局样式表,则必须覆盖从该规则继承的选项标签的样式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      相关资源
      最近更新 更多