目录

如何操作 - 接触式芯片


了解如何使用 CSS 创建接触片。


接触式芯片

Person约翰·多伊
Person简·罗 ×

创建接触芯片

步骤1)添加HTML:

示例

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

步骤2)添加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 事件属性的元素,该属性显示 "when you click you on me, hide my parent element" - 这是容器 div (class="chip")。

示例

<div class="chip">
  <img src="img_avatar.jpg" alt="Person" width="96" height="96">
  John Doe
  <span class="closebtn" onclick="this.parentElement.style.display='none'">&times;</span>
</div>

提示:使用 HTML 实体“&times;" to create the letter "x"。

接下来,设置关闭按钮的样式:

示例

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

.closebtn:hover {
  color: #000;
}
亲自试一试 »