带旋转卡的Bootstrap 4

时间:2018-06-04 09:36:48

标签: html css bootstrap-4

我正在使用Bootstrap v4(仅包含行和列)创建自己的卡。问题是当我试图将卡的两侧放在彼此的顶部时。我使用position: absolute;他们完全消失了



.thecard {
  perspective: 150rem;
  -moz-perspective: 150rem;
  position: relative;
}

.thecard__side {
  background-color: orangered;
  color: #fff;
  font-size: 2rem;
  height: 50rem;
  transition: all .8s;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  backface-visibility: hidden;
}

.thecard__side--front {
  background-color: orangered;
}

.thecard__side--back {
  background-color: green;
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.thecard:hover .thecard__side--front {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.thecard:hover .thecard__side--back {
  -webkit-transform: rotateY(0);
  transform: rotateY(0);
}

<div class="row mt-5">
  <div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
    <div class="thecard">
      <div class="thecard__side thecard__side--front">
        Front
      </div>
      <div class="thecard__side thecard__side--back">
        Back
      </div>
    </div>
  </div>
  <div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
    <div class="thecard">
      <div class="thecard__side thecard__side--front">
        Front
      </div>
      <div class="thecard__side thecard__side--back">
        Back
      </div>
    </div>
  </div>
  <div class=" offset-md-3 mt-5 mt-lg-0 offset-lg-0 col-md-6 col-lg-4">
    <div class="thecard">
      <div class="thecard__side thecard__side--front">
        Front
      </div>
      <div class="thecard__side thecard__side--back">
        Back
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

任何解决方案的人?

2 个答案:

答案 0 :(得分:0)

经过多次测试,这两个类的相同高度为我解决了问题:

 .thecard {
      perspective: 150rem;
      -moz-perspective: 150rem;
      position: relative;
      height: 50rem; 
    }

    .thecard__side {
      background-color: orangered;
      color: #fff;
      font-size: 2rem;
      height: 50rem;
      transition: all .8s;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      backface-visibility: hidden;
    }

答案 1 :(得分:0)

您可以试用此代码

.thecard {
  perspective: 150rem;
  -moz-perspective: 150rem;
  position: relative;
  height: 350px;
}

.thecard__side {
  background-color: orangered;
  color: #fff;
  font-size: 2rem;
  height: 50rem;
  transition: all .8s;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  backface-visibility: hidden;
}

.thecard__side--front {
  background-color: orangered;
}

.thecard__side--back {
  background-color: green;
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.thecard:hover .thecard__side--front {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.thecard:hover .thecard__side--back {
  -webkit-transform: rotateY(0);
  transform: rotateY(0);
}
<div class="row mt-5">
  <div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
    <div class="thecard">
      <div class="thecard__side thecard__side--front">
        Front
      </div>
      <div class="thecard__side thecard__side--back">
        Back
      </div>
    </div>
  </div>
  <div class="mt-5 mt-lg-0 col-md-6 col-lg-4">
    <div class="thecard">
      <div class="thecard__side thecard__side--front">
        Front
      </div>
      <div class="thecard__side thecard__side--back">
        Back
      </div>
    </div>
  </div>
  <div class=" offset-md-3 mt-5 mt-lg-0 offset-lg-0 col-md-6 col-lg-4">
    <div class="thecard">
      <div class="thecard__side thecard__side--front">
        Front
      </div>
      <div class="thecard__side thecard__side--back">
        Back
      </div>
    </div>
  </div>
</div>