如何創建:聯系人芯片

學習如何使用 CSS 創建聯系人芯片。

聯系人芯片

Person Bill Gates
Person Jane Row ×

創建聯系人芯片

第一步 - 添加 HTML:

<div class="chip">
  <img src="img_avatar.jpg" alt="Person" width="96" height="96">
  Bill Gates
</div>

第二步 - 添加 CSS:

.chip {
  display: inline-block;
  padding: 0 25px;
  height: 50px;
  font-size: 16px;
  line-height: 50px;
  border-radius: 25px;
  background-color: #f1f1f1;
}
.chip img {
  float: left;
  margin: 0 10px 0 -25px;
  height: 50px;
  width: 50px;
  border-radius: 50%;
}

親自試一試

可關閉的聯系人芯片

要關閉/隱藏聯系人芯片,請添加一個帶有 onclick 事件屬性的元素,該屬性表示“當你點擊我時,隱藏我的父元素” - 即容器 <div class="chip">

實例

<div class="chip">
  <img src="img_avatar.jpg" alt="Person" width="96" height="96">
  Bill Gates
  <span class="closebtn" onclick="this.parentElement.style.display='none'">×</span>
</div>

提示:請使用 HTML 實體 "&times;" 創建字母 "x"。

接下來,設置關閉按鈕的樣式:

實例

.closebtn {
  padding-left: 10px;
  color: #888;
  font-weight: bold;
  float: right;
  font-size: 20px;
  cursor: pointer;
}
.closebtn:hover {
  color: #000;
}

親自試一試