Angular host 样式

分类:HTML&CSS     发布时间:2021-02-23     最后更新:2021-02-24     浏览数:2679
Angular host 样式

使用

<div>
  <sp-circle color="red" size="mini"></sp-circle>
  <sp-circle color="green" size="mini"></sp-circle>
  <sp-circle color="gray" size="mini"></sp-circle>
  <sp-circle color="empty" size="mini"></sp-circle>
</div>

<div>
  <sp-circle color="red"></sp-circle>
  <sp-circle color="green"></sp-circle>
  <sp-circle color="gray"></sp-circle>
  <sp-circle color="empty"></sp-circle>
</div>

组件样式

:host {
  display: inline-block;
  width: 24px;
  height: 24px;
  box-sizing: border-box;
  background-color: transparent;
  border: 3px solid transparent;
  border-radius: 50%;
}

:host[color=red] {
  background-color: #ff4a44;
  border-color: #ff8285;
}

:host[color=green] {
  background-color: #14a23a;
  border-color: #51bb79;
}

:host[color=gray] {
  background-color: #4a4b4e;
  border-color: #878789;
}

:host[color=empty] {
  border-color: #646567;
}

:host[size=mini] {
  width: 8px;
  height: 8px;
  border-width: 2px;
}

// 如果是类,可以这样写
:host(.active) {
    border-color: red;
}

效果

圆点

参考

Angular 2 HostListener & HostBinding

上一篇: 使用 Angular pipe 过滤、排序、分页 下一篇: 我的微信小程序项目