如何使用 CSS 建立聯絡片?
聯絡片可以在網頁上視為小型的聯絡人卡片。如果你要在一個網頁上列出多個支援人員或團隊成員,則要正確對齊其詳細資訊,請使用聯絡片。其中只包含姓名的小型個人資料圖片。接下來看看如何使用 HTML 和 CSS 在網頁上建立聯絡片。
建立容器
對於聯絡片,請建立單獨的容器。首先,使用 <img> 元素包括個人資料圖片。使用 src 屬性添加個人資料圖片的圖片源 −
<div class="chip"> <img src="https://tutorialspoint.tw/assets/profiles/123055/profile/200_187394-1565938756.jpg" alt ="Amit"> Amit Diwan </div> <div class="chip"> <img src="https://cdn.pixabay.com/photo/2014/03/24/17/19/teacher-295387__340.png" alt="Britney"> Britney Smith </div>
定位聯絡片
要定位聯絡片,最佳的解決方案是將 display 屬性設為 inline-block。要設計聯絡片,請使用 border-radius 屬性 −
.chip {
display: inline-block;
padding: 0 25px;
height: 50px;
font-size: 20px;
font-weight: bold;
line-height: 50px;
border-radius: 25px;
background-color: #6a0074;
color: white;
}
定位聯絡圖片
聯絡片上的個人資料圖片使用 float 屬性浮動在左側,值為 left。此外,border-radius 又發揮了關鍵作用,用於塑造圖片 −
.chip img {
float: left;
margin: 0 10px 0 -25px;
height: 50px;
width: 50px;
border-radius: 50%;
}
示例
使用 CSS 建立聯絡片,程式碼如下 −
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin:25px;
}
.chip {
display: inline-block;
padding: 0 25px;
height: 50px;
font-size: 20px;
font-weight: bold;
line-height: 50px;
border-radius: 25px;
background-color: #6a0074;
color: white;
}
.chip img {
float: left;
margin: 0 10px 0 -25px;
height: 50px;
width: 50px;
border-radius: 50%;
}
</style>
</head>
<body>
<h1>Contact chip Example</h1>
<div class="chip">
<img src="https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909__340.png">
James Anderson
</div>
<div class="chip">
<img src="https://cdn.pixabay.com/photo/2014/03/24/17/19/teacher-295387__340.png">
Britney Smith
</div>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP