angularjs - 如何设置border-right : none in a label for the last child?

标签 angularjs html css sass

我有一个 label,它在我的一个 div 中返回不同的名称(很多),这是它在 html View 中的样子。

<div class="customerDisplayFlex">
      <div class="" *ngFor="let cust of customers">
     <label class="dataLabel">
          <input type="radio"
                  name="user-radio"
                  [value]="customer"
                  [ngModel]="currentCustomerContext"
                  (click)="onCustomerContextchange(customer)"
                  class="dataLabel__input" />

          <span class="customer__label">{{customer.firstName | titleCase}} {{ customer.lastName | titleCase}}</span>
        </label>
</div>
</div>

这是 View 的CSS

.dataLabel{
color: green;
border-right: 2px solid grey;
}
.dataLabel:last-child{
border-right: none;
}

我什至尝试使用 sass:

.dataLabel{
    color: green;
    border-right: 2px solid grey;
&:last-child{
border-right: none;
}
}

以一种奇怪的方式,这不起作用,我在这里做错了什么?有人可以帮忙吗?谢谢

最佳答案

你不需要:last-child,你想要:last-of-type:

.dataLabel {
  color: green;
  border-right: 2px solid grey;
}

.dataLabel:last-of-type {
  border-right: none;
}
<div class="customerDisplayFlex">
  <div class="" *ngFor="let cust of customers">
    <label class="dataLabel">Label 1</label>
    <label class="dataLabel">Label 2</label>
    <label class="dataLabel">Label 3</label>
  </div>
</div>

⋅ ⋅ ⋅

然后,您甚至可以使用 :not 选择器来增强代码,如下所示:

.dataLabel {
  color: green;
}

.dataLabel:not(:last-of-type) {
  border-right: 2px solid grey;
}
<div class="customerDisplayFlex">
  <div class="" *ngFor="let cust of customers">
    <label class="dataLabel">Label 1</label>
    <label class="dataLabel">Label 2</label>
    <label class="dataLabel">Label 3</label>
  </div>
</div>

希望对您有所帮助。

关于angularjs - 如何设置border-right : none in a label for the last child?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50427099/

相关文章:

javascript - 地理定位 watch 不会持续触发

javascript - 背景图像 jQuery 不工作,我做错了什么?

css - 改变 ui.bootstrap.alert 的高度

javascript - 在 for 循环中合并 $http.get JSON 数据

javascript - 更新注入(inject)的服务后刷新 AngularJS 过滤器

javascript - 不将数组中的图像添加到 div 背景

html - 在 React 中添加组件会导致水平滚动条

javascript - AngularJS在指令模板中执行 Controller 函数

javascript - 在 Protractor 中加载页面之前单击对话框

javascript - 如何在 HTML5 Canvas 中显示 tQuery.World