javascript - 使用这个 CSS 转换的翻盖卡片,我怎样才能保持后面的内容可访问?
问题描述
我有一张翻转卡片,我希望它的两面都能够点击和编辑内容可编辑,但我相信由于实现翻转变换涉及的 CSS,我只能访问正面;当卡片被翻转时,背面无法点击。我该如何解决?
class Card {
constructor() {
this.wrapper = document.createElement("div");
this.wrapper.className = "wrapper stowed";
this.card = document.createElement("div");
this.card.className = "card";
this.front = document.createElement("div");
this.front.className = "front";
this.front.contentEditable = true;
this.front.innerHTML = "Prompt";
this.back = document.createElement("div");
this.back.className = "back";
this.back.contentEditable = true;
this.back.innerHTML = "Answer";
this.card.appendChild(this.front);
this.card.appendChild(this.back);
this.wrapper.appendChild(this.card);
document.body.appendChild(this.wrapper);
}
}
let card = new Card();
@import url('https://fonts.googleapis.com/css?family=Raleway:300');
body {
font-size:25px;
font-family: 'Raleway', sans-serif;
margin: 0;
background-color: #39243b;
overflow:hidden;
display:flex;
align-items:center;
justify-content:center;
height:100vh;
}
.wrapper {
display:flex;
align-items:center;
justify-content:center;
}
.card {
transition: transform 2s;
width: 600px;
height: 300px;
transform: perspective(800px);
backface-visibility: hidden;
position:relative;
transform-style: preserve-3d;
}
.front, .back {
backface-visibility: hidden;
position:absolute;
border-radius: 10px;
width:100%;
display:flex;
height:100%;
text-align:center;
align-items:center;
justify-content:center;
font-family: 'Raleway', sans-serif;
background-color:white;
}
.back {
backface-visibility: hidden;
z-index: 1;
transform: rotateY(180deg) rotateZ(180deg);
}
.front {
z-index: 2;
transform: perspective(800px);
}
.wrapper:hover .card {
transform: perspective(800px) rotateX(180deg);
}
如您所见,问题在这里完美重现,至少在 Chrome 中查看。
解决方案
删除backface-visibility: hidden
,.card
问题就消失了。
class Card {
constructor() {
this.wrapper = document.createElement("div");
this.wrapper.className = "wrapper stowed";
this.card = document.createElement("div");
this.card.className = "card";
this.front = document.createElement("div");
this.front.className = "front";
this.front.contentEditable = true;
this.front.innerHTML = "Prompt";
this.back = document.createElement("div");
this.back.className = "back";
this.back.contentEditable = true;
this.back.innerHTML = "Answer";
this.card.appendChild(this.front);
this.card.appendChild(this.back);
this.wrapper.appendChild(this.card);
document.body.appendChild(this.wrapper);
}
}
let card = new Card();
@import url('https://fonts.googleapis.com/css?family=Raleway:300');
body {
font-size:25px;
font-family: 'Raleway', sans-serif;
margin: 0;
background-color: #39243b;
overflow:hidden;
display:flex;
align-items:center;
justify-content:center;
height:100vh;
}
.wrapper {
display:flex;
align-items:center;
justify-content:center;
}
.card {
transition: transform 2s;
width: 600px;
height: 300px;
transform: perspective(800px);
/*backface-visibility: hidden;*/
position:relative;
transform-style: preserve-3d;
}
.front, .back {
backface-visibility: hidden;
position:absolute;
border-radius: 10px;
width:100%;
display:flex;
height:100%;
text-align:center;
align-items:center;
justify-content:center;
font-family: 'Raleway', sans-serif;
background-color:white;
}
.back {
backface-visibility: hidden;
z-index: 1;
transform: rotateY(180deg) rotateZ(180deg);
}
.front {
z-index: 2;
transform: perspective(800px);
}
.wrapper:hover .card {
transform: perspective(800px) rotateX(180deg);
}
推荐阅读
- amazon-web-services - 到 ES 的 Logstash 输出给了我错误代码“400”
- python - Python 字典辅助
- postgresql - 如何选择带有柴油 rs 的列子集?
- javascript - JavaScript - POST 到 URL 不发送数据
- ios - MobSF:解决@rpath 违规问题
- python-3.x - 有人可以解释一下这个声明对图像的作用吗?图像 = 图像[60:-25, 0:, 0:]
- windows-subsystem-for-linux - 通过“wsl [command]”调用命令与打开 wsl shell 并调用“[command]”有什么区别?
- c - MakeFile 的子目录和 GCC 问题
- python - 通过计算已处理的图像来显示 for 循环的进度 [Python]
- c# - C++ 到 C# 使用联合对嵌套结构进行编组