css 为什么我的记事卡会以这种奇怪的方式翻转文字?

f87krz0w  于 2023-03-09  发布在  其他
关注(0)|答案(2)|浏览(141)

我正在做一个网站,把文本转换成记事卡,我在动画上很纠结,不管我怎么做,3d动画似乎把文本弄乱了,镜像了它,我试过玩css,但我是网络开发新手,这太多了。
下面是存储库:https://github.com/Subwaey/Notes2Cards
一张图片:

简化代码:

function flipAll() {
  const cards = document.querySelectorAll('.card');

  cards.forEach(card => {
    card.addEventListener('click', () => {
      card.classList.toggle('flipped');
    });
  });
}

const flashcards = document.getElementById("flashcards");
flashcards.innerHTML = "";

var terms = ["a", "b", "c"];
var definitions = ["aa", "bb", "cc"];

for (let i = 0; i < terms.length; i++) {
  const card = document.createElement("div");
  card.classList.add("card");

  const cardInner = document.createElement("div");
  cardInner.classList.add("card-inner");
  card.appendChild(cardInner);

  const cardFront = document.createElement("div");
  cardFront.classList.add("card-front");
  cardFront.innerHTML = `<h2>${terms[i]}</h2>`;
  cardInner.appendChild(cardFront);

  const cardBack = document.createElement("div");
  cardBack.classList.add("card-back");
  cardBack.innerHTML = `<p>${definitions[i]}</p>`;
  cardInner.appendChild(cardBack);

  card.addEventListener("click", function() {
    card.classList.toggle("flipped");
  });

  flashcards.appendChild(card);
}
.card {
  width: 400px;
  height: 250px;
  background-color: #252525;
  border-radius: 10px;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s;
  margin: 50px auto;
  position: relative;
}

.card:hover {
  transform: scale(1.05);
  background-color: #2e2e2e;
}

.card .card-inner {
  position: absolute;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.3s;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.card .card-front,
.card .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card .card-front {
  transform: rotateY(0deg);
}

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

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card.flipped {
  transform: rotateY(180deg);
}

.card.flipped .card-front {
  transform: rotateY(0deg);
}
<div class="grid" id="flashcards"></div>
mzsu5hc0

mzsu5hc01#

如果你转换里面的内容,你可以让它以正确的方式翻转

.card .card-back p {
  transform: rotateY(180deg);
}

x一个一个一个一个x一个一个二个一个x一个一个三个一个

3vpjnl9f

3vpjnl9f2#

styles.css中删除以下内容。

.card.flipped {
transform: rotateY(180deg);
}

您已经在使用card-inner进行轮转

相关问题