만드는 방법: 뒤집히는 카드

CSS를 사용하여 뒤집히는 카드를 만들어보세요.

아래 그림에 마우스를 가져가세요:

아바타
빌 게이츠

건축가 & 공학자

저는 그 사람을 사랑합니다

직접 시도해보세요

뒤집히는 카드를 만들기

첫 번째 단계 - HTML 추가:

<div class="flip-card">
  <div class="flip-card-inner">
    <div class="flip-card-front">
      <img src="img_avatar.png" alt="Avatar" style="width:300px;height:300px;">
    </div>
    <div class="flip-card-back">
      <h1>Bill Gates</h1>
      <p>Architect & Engineer</p>
      <p>We love that guy</p>
    </div>
  </div>
</div>

第二步 - 添加 CSS:

/* 翻转卡片的容器 - 设置你想要的宽度和高度。我们添加了 border 属性来演示翻转本身在悬停时会超出容器(如果您不想要 3D 效果,请删除透视图) */
.flip-card {
  background-color: transparent;
  width: 300px;
  height: 200px;
  border: 1px solid #f1f1f1;
  perspective: 1000px; /* 如果您不想要 3D 效果,请将其删除 */
{}
/* 这个容器用于定位正面和背面 */
.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.8s;
  transform-style: preserve-3d;
{}
/* 当鼠标悬停在翻转卡片容器上时,进行水平翻转 */
.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
{}
/* 定位正面和背面 */
.flip-card-front, .flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden; /* Safari */
  backface-visibility: hidden;
{}
/* 设置正面的样式(如果图像缺失则备用) */
.flip-card-front {
  background-color: #bbb;
  color: black;
{}
/* 设置背面的样式 */
.flip-card-back {
  background-color: dodgerblue;
  color: white;
  transform: rotateY(180deg);
{}

직접 시도해보세요