html - 如何垂直对齐此图像?

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

最佳答案

您在 flip-card 类中提到了 float:left,删除该类中的 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>

关于html - 如何垂直对齐此图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58258739/

相关文章:

Javascript 在 HTML 文件中有效,但在 Javascript 文件中无效

html - Bootstrap 5个元素,在不同设备上的不同配置

jquery - Bootstrap 表头问题

asp.net - Div 背景在 V9 之前的任何 IE 中都不显示

javascript - jQuery 获取调用脚本标签的引用

javascript - 如何从桌面网页隐藏菜单按钮?

css - 自定义桌面上的 Bootstrap 列排列

angularjs - 在 angularjs 的 Bootstrap 中覆盖 Bootstrap Accordion 颜色

javascript - 如何在单击按钮时选中复选框

HTML - 如何左对齐保持在表格的中心?