Cómo crear: Chip de contacto

Aprende a usar CSS para crear un chip de contacto.

Chip de contacto

Persona Bill Gates
Persona Jane Row ×

Crear chip de contacto

Primer paso - Añadir HTML:

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

Segundo paso - Añadir 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%;
}

Prueba personal

Chip de contacto cerrable

Para cerrar/ocultar el chip de contacto, agregue un onclick Elemento con atributo de evento, que representa "cuando me haces clic, oculta mi elemento padre" - es decir, el contenedor <div class="chip">.

Ejemplo

<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>

Consejo:Por favor, utilice el entero HTML "×"Crear la letra "x"."

A continuación, configure el estilo del botón de cerrar:

Ejemplo

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

Prueba personal