【问题标题】:Why 'backface-visibility: hidden' does not work with text?为什么“背面可见性:隐藏”不适用于文本?
【发布时间】:2022-01-13 20:01:45
【问题描述】:

这应该是一个记忆游戏,上面有文字的卡片。

正面的卡片应该是白色的(背景图像),背面有一个单词。但是由于应用了 backface-visibility-hidden,它实际上只显示了背景图像,没有文字。

它应该只有背面的文字,但出于好奇,我将文字放在背面和正面的一张卡片上,只有这张显示正面的文字,但翻转后不显示背面文字,但只是正面的镜像。

我已经阅读了 IE 可能会导致问题,但在这种情况下不会,因为它在任何浏览器中都不起作用。

我尝试过使用 preserve-3d,但没有任何解决方案。

<section class="memory-game">
      <div class="memory-card">
        <p class="front">un abricot</p>
        <p class="back"></p>
      </div>
</section>
.memory-game {
  
  perspective: 1000px;
}

.memory-card {
  
  position: relative;
  transform: scale(1);
  transition: transform 0.4s;
}

.memory-card:active {
  transform: scale(0.95);
  transition: transform 0.4s;
}

.memory-card.flip {
  transform: rotateY(180deg);
}

.front,
.back {
  position: absolute;
  background-image: url("image.jpg");
  backface-visibility: hidden;
}

.front {
  transform: rotateY(180deg);
}

back

front

disappearing half

【问题讨论】:

标签: html css transform css-transforms preserve-3d


【解决方案1】:

如你所说,解决方案是添加preserve-3d。

查看它在 sn-p 中的工作

.memory-game {
  
  perspective: 1000px;
}

* {
    transform-style: preserve-3d;
}

.memory-card {
  
  position: relative;
  transform: scale(1);
  transition: transform 0.4s;
  border: solid 1px black;
  height: 50px;
  width: 200px;
}

.memory-card:active {
  transform: scale(0.95);
  transition: transform 0.4s;
}

body:hover .memory-card  {
  transform: rotateY(180deg);
}

.front,
.back {
  position: absolute;
  background-image: url("image.jpg");
  backface-visibility: hidden;
}

.front {
  transform: rotateY(180deg);
}
<section class="memory-game">
      <div class="memory-card">
        <p class="front">FRONT</p>
        <p class="back">BACK</p>
      </div>
</section>

【讨论】:

  • 是的,这行得通。太感谢了。我已经应用了这个并逐步添加了我的样式。背景滤镜:模糊(5px)饱和(120%);我也包括在内以及许多其他样式搞砸了。不过,我不知道为什么...我希望边缘模糊,并在背景中显示白色图像,但我想我只需要制作一个具有透明度的 png。
  • 过滤器应用于元素的“扁平化”版本,因此不可能同时拥有这两种东西(过滤器和preserve-3d)
  • 好吧,我知道了,我猜。永远不能拥有这一切...... :)
  • 现在只发生了一件事。点击卡片的一半后消失,只有在完成转换后才会显示,因为我在帖子的编辑部分发布了底部。
  • 好的,只将preserve-3d添加到父元素修复了这一切。
猜你喜欢
  • 2014-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-27
  • 1970-01-01
  • 2015-10-29
  • 1970-01-01
相关资源
最近更新 更多