【问题标题】:How to remove the border of last child in list items using after如何使用after删除列表项中最后一个子项的边框
【发布时间】:2022-02-11 22:42:44
【问题描述】:

在我的应用程序中,我在列表项中的 i 标记中有一些字体图标,并且在每个图标之后我放置了一些边框线。

但我的要求是删除列表项中最后一个元素的边框。

.component.html

<div class="list-container">
<ul>
   <li *ngFor="let icon of iconsArr">
    <span class="icons" [style.font-weight]="icon.active ? 'bold' : 'normal'" ></span><i (click)="onIconClick(icon)" class="smiley-icon "   [ngClass]="icon.class"
    [style.color]="icon.active === true ? '#FF0000' : '#ffffff'" >
   
 </i>
   </li>
 </ul>
      </div>

.component.css

.list-container{
  li{
    display: inline;
  }
.icons{
    font-size: 2.9em;
    display:inline-block;
    margin: 0px;
    text-shadow: -1.3px 0 #000, 0 1.3px #000, 1.3px 0 #000, 0 -1.3px #000;
    color: white;
    margin-right: -8.9px;
    //z-index:1000;
}
 .icons::after{
    content: "";
    display: inline-block;
    width: 0.8em;
    border-top: 5px solid #e8e8e8;
    top: 50%;
    z-index: -10;
    margin-bottom: 15px;
    margin-left: -8px;
}

如果我写


.icons:last-of-type:after{
content:"";
border:none;
}

它不起作用,我想从图标列表中删除最后一个图标的边框

【问题讨论】:

    标签: html css css-selectors pseudo-element


    【解决方案1】:
    ul li:last-of-type .icons {
        border: none;
    }
    

    请尝试类似的方法,或者

    ul li:last-of-child .icons {
        border: none;
    }
    

    【讨论】:

      【解决方案2】:

      您要定位的最后一个子元素是 li 元素而不是 span。

      所以使用:

      .list-container ul li:last-child span.icons::after {
        border: none;
      }
      

      【讨论】:

        猜你喜欢
        • 2023-01-12
        • 1970-01-01
        • 2018-05-25
        • 2020-02-09
        • 1970-01-01
        • 2013-08-12
        • 1970-01-01
        • 2017-01-14
        • 1970-01-01
        相关资源
        最近更新 更多