背面可见性仅部分起作用

时间:2018-06-07 00:08:19

标签: html css css3 animation sass

我正在尝试制作一张在悬停时翻转的卡片。为了隐藏卡片的后部,我使用了backface-visibility:hidden。但它只隐藏了后部的背景,而所有的元素在旋转的变体中仍然可以在前侧看到。 我使用谷歌浏览器。

这是我的HTML代码

<div class="card">

    <div class="card__side card__side--front">
      <div class="card__picture card__picture--1"></div>
      <div class="card__heading">
        <span class="card__heading-span card__heading-span--1">
          The sea explorer
        </span>
      </div>
      <div class="card__details">
        <ul class="card__list">
          <li class="card__item">3 day tour</li>
          <li class="card__item">Up to 30 people</li>
          <li class="card__item">2 tour guides</li>
          <li class="card__item">Sleep in cozy hotels</li>
          <li class="card__item">Difficulty: easy</li>
        </ul>
      </div>
    </div>

    <div class="card__side card__side--back card__side--back-1">
      <div class="card__cta">
        <div class="card__price-box">
          <p class="card__price--only">Only</p>
          <p class="card__price--value">$297</p>
        </div>
        <a href="#popup" class="btn btn--white">Book now</a>
      </div>
    </div>

  </div>

这是我的SASS代码

.card {
position: relative;
height: 52rem;

perspective: 150rem;

&__side {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 52rem;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 1.5rem 4rem rgba($color-black, .15);

  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition: all .8s ease;

  &--front {
    background-color: $color-white;
  }

  &--back {
    transform: rotateY(180deg);

    &-1 {
      background-image:
          linear-gradient(to right bottom,$color-secondary-light,$color-secondary-dark);
    }
    &-2 {}
    &-3 {}

  }
}

&:hover &__side--front {
  transform: rotateY(-180deg);
}

&:hover &__side--back {
  transform: rotateY(0);
}

// Front side styles

&__picture {

  &--1 {}
  &--2 {}
  &--3 {}
}

&__heading {

}

&__heading-span {

  &--1 {}
  &--2 {}
  &--3 {}
}

&__details {

}

&__list {
  width: 80%;
  margin: 0 auto;

  list-style-type: none;
}

&__item {

  &:not(:last-child) {
    border-bottom: 1px solid $color-gray-light-2;
  }
}

//Back side styles

&__cta {
  @include absoluteCenter();
  width: 90%;

  text-align: center;
}

&__price-box {
  margin-bottom: 6rem;
  color: $color-black;
  text-align: center;
}

&__price--only {
  font-size: 1.4rem;
  text-transform: uppercase;
}

&__price--value {
  font-size: 6rem;
  font-weight: 300;
}
}

这就是问题在Chrome中的实际情况。enter image description here

1 个答案:

答案 0 :(得分:-1)

添加transform-style:preserve-3d到.card而不是.card__side为我修复了这个bug。