如何創建:卡片

學習如何使用 CSS 創建“卡片”。

Avatar
Bill Gates

Architect & Engineer

Avatar
Jane Doe

Interior Designer

親自試一試

如何創建卡片

第一步 - 添加 HTML:

<div class="card">
  <img src="img_avatar.png" alt="Avatar" style="width:100%">
  <div class="container">
    <h4><b>Bill Gates</b></h4>
    <p>Architect & Engineer</p>
  </div>
</div>

第二步 - 添加 CSS:

.card {
  /* 添加陰影以創建“卡片”效果 */
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  transition: 0.3s;
}
/* 當鼠標懸停時,添加更深的陰影 */
.card:hover {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
/* 在卡片容器內部添加一些內邊距 */
.container {
  padding: 2px 16px;
}

親自試一試

帶圓角:

實例

.card {
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  transition: 0.3s;
  border-radius: 5px; /* 5px rounded corners */
}
/* 為圖像的左上角和右上角添加圓角 */
img {
  border-radius: 5px 5px 0 0;
}

親自試一試

相關頁面

教程:CSS 陰影效果