如何垂直对齐此图像?

时间:2019-10-06 15:29:41

标签: html css twitter-bootstrap

如何在此动画div中垂直对齐此图像?

.flip-card {
  background-color: transparent;
  float: left;
  height: auto;
  max-height: 25%;
  perspective: 1000px;
  /* Remove this if you don't want the 3D effect */
  overflow: hidden;
}

.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%;
  backface-visibility: hidden;
}

.flip-card-front {
  background-color: transparent;
  color: black;
}

.flip-card-back {
  background-color: dodgerblue;
  color: white;
  font-size: 2vmin;
  transform: rotateY(180deg);
}
<div class="flip-card col-4">
  <div class="flip-card-inner">
    <div class="flip-card-front">
      <img src="https://via.placeholder.com/468x60?text=40%%20Off" class="img-fluid img-discount" alt="Avatar" style="width:300px;height:300px;">
    </div>
    <div class="flip-card-back">
      <span style="font-weight: bold; font-size:3vmax; color: #fff">Text</span>
      <p>Text</p>
      <p>Text</p>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

您在float:left类中提到了flip-card,请删除该类中的float:left,它将起作用。

<!DOCTYPE html>
<html>
<head>
<style>
.flip-card {
  background-color: transparent;
  
  height: auto;
  max-height: 25%;
  perspective: 1000px; /* Remove this if you don't want the 3D effect */
 
}

 .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%;
  backface-visibility: hidden;
}

.flip-card-front {
  background-color: transparent;
  color: black;
}

.flip-card-back {
  background-color: dodgerblue;
  color: white;
  font-size: 2vmin;
  transform: rotateY(180deg);
}

.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}
</style>
</head>
<body>

<div class="flip-card col-4">
<div class="flip-card-inner">
<div class="flip-card-front">
  <img src="https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" class="img-fluid img-discount" alt="Avatar" style="width:300px;height:300px;">
</div>
<div class="flip-card-back">
  <span style="font-weight: bold; font-size:3vmax; color: #fff">Text</span>
  <p>Text</p> 
  <p>Text</p>
</div>

</body>
</html>