为什么我无法在 Chrome 中单击此 CSS 翻转卡片上 link 的左侧?
Why can't I click the left side of the link on this CSS flip card in Chrome?
尝试点击此翻转卡片背面 link 的 左侧 侧在 Chrome 中不起作用。然而,当我将鼠标悬停在 link 的 右侧 一侧时,我看到了指针光标并且能够与之交互:
/* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */
.card {
-webkit-perspective: 1000px;
perspective: 1000px;
display: inline-block;
}
.card .card-inner {
position: relative;
-webkit-transition: -webkit-transform 0.6s;
transition: -webkit-transform 0.6s;
-o-transition: transform 0.6s;
transition: transform 0.6s;
transition: transform 0.6s, -webkit-transform 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
}
.card .card-inner .card-face {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card .card-inner .card-face.card-back {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-inner .card-face .card-face-inner .card-face-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 22px;
}
.card:hover .card-inner {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-back {
background: steelblue;
}
<div class="card">
<div class="card-inner">
<img src="https://via.placeholder.com/400x500?text=%20" alt="" />
<div class="card-face card-front">
<div class="card-face-inner">
<div class="card-face-content">
Front
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-face-inner">
<div class="card-face-content">
<a href="#foo">Back</a>
</div>
</div>
</div>
</div>
</div>
如何解决这个问题,使整个 link 都可以点击?我猜这与 backface-visibility
有关。我遇到了 this Whosebug answer,但我认为解决方案已经在此处实施了以下几行:
.card .card-inner {
...
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
我不知道 原因 但这很可能是一个错误,因为它可以按预期在 Firefox 上运行。将 pointer-events: none;
添加到 .card-inner
并将 pointer-events: auto
添加到 .card-face
有效,只有天知道为什么。
/* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */
.card {
-webkit-perspective: 1000px;
perspective: 1000px;
display: inline-block;
}
.card .card-inner {
position: relative;
-webkit-transition: -webkit-transform 0.6s;
transition: -webkit-transform 0.6s;
-o-transition: transform 0.6s;
transition: transform 0.6s;
transition: transform 0.6s, -webkit-transform 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
pointer-events: none;
}
.card .card-inner .card-face {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
pointer-events: auto;
}
.card .card-inner .card-face.card-back {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-inner .card-face .card-face-inner .card-face-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 22px;
}
.card:hover .card-inner {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-back {
background: steelblue;
}
<div class="card">
<div class="card-inner">
<img src="https://via.placeholder.com/400x500?text=%20" alt="" />
<div class="card-face card-front">
<div class="card-face-inner">
<div class="card-face-content">
Front
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-face-inner">
<div class="card-face-content">
<a href="#foo">Back</a>
</div>
</div>
</div>
</div>
</div>
原因是由于 Chrome 中的小精度误差,180 度不完全是半圈。
并且元素的左侧在前面下面(即使你看不到它,它仍然存在)。
在 Z 方向升高你的元素,只是一个像素,并且它起作用了(现在它完全在另一边):
/* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */
.card {
-webkit-perspective: 1000px;
perspective: 1000px;
display: inline-block;
}
.card .card-inner {
position: relative;
-webkit-transition: -webkit-transform 0.6s;
transition: -webkit-transform 0.6s;
-o-transition: transform 0.6s;
transition: transform 0.6s;
transition: transform 0.6s, -webkit-transform 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
}
.card .card-inner .card-face {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card .card-inner .card-face.card-back {
transform: rotateY( 180deg) translateZ(1px); /* changed */
}
.card .card-inner .card-face .card-face-inner .card-face-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 22px;
}
.card:hover .card-inner {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-back {
background: steelblue;
}
<div class="card">
<div class="card-inner">
<img src="https://via.placeholder.com/400x500?text=%20" alt="" />
<div class="card-face card-front">
<div class="card-face-inner">
<div class="card-face-content">
Front
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-face-inner">
<div class="card-face-content">
<a href="#foo">Back</a>
</div>
</div>
</div>
</div>
</div>
尝试点击此翻转卡片背面 link 的 左侧 侧在 Chrome 中不起作用。然而,当我将鼠标悬停在 link 的 右侧 一侧时,我看到了指针光标并且能够与之交互:
/* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */
.card {
-webkit-perspective: 1000px;
perspective: 1000px;
display: inline-block;
}
.card .card-inner {
position: relative;
-webkit-transition: -webkit-transform 0.6s;
transition: -webkit-transform 0.6s;
-o-transition: transform 0.6s;
transition: transform 0.6s;
transition: transform 0.6s, -webkit-transform 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
}
.card .card-inner .card-face {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card .card-inner .card-face.card-back {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-inner .card-face .card-face-inner .card-face-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 22px;
}
.card:hover .card-inner {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-back {
background: steelblue;
}
<div class="card">
<div class="card-inner">
<img src="https://via.placeholder.com/400x500?text=%20" alt="" />
<div class="card-face card-front">
<div class="card-face-inner">
<div class="card-face-content">
Front
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-face-inner">
<div class="card-face-content">
<a href="#foo">Back</a>
</div>
</div>
</div>
</div>
</div>
如何解决这个问题,使整个 link 都可以点击?我猜这与 backface-visibility
有关。我遇到了 this Whosebug answer,但我认为解决方案已经在此处实施了以下几行:
.card .card-inner {
...
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
我不知道 原因 但这很可能是一个错误,因为它可以按预期在 Firefox 上运行。将 pointer-events: none;
添加到 .card-inner
并将 pointer-events: auto
添加到 .card-face
有效,只有天知道为什么。
/* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */
.card {
-webkit-perspective: 1000px;
perspective: 1000px;
display: inline-block;
}
.card .card-inner {
position: relative;
-webkit-transition: -webkit-transform 0.6s;
transition: -webkit-transform 0.6s;
-o-transition: transform 0.6s;
transition: transform 0.6s;
transition: transform 0.6s, -webkit-transform 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
pointer-events: none;
}
.card .card-inner .card-face {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
pointer-events: auto;
}
.card .card-inner .card-face.card-back {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-inner .card-face .card-face-inner .card-face-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 22px;
}
.card:hover .card-inner {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-back {
background: steelblue;
}
<div class="card">
<div class="card-inner">
<img src="https://via.placeholder.com/400x500?text=%20" alt="" />
<div class="card-face card-front">
<div class="card-face-inner">
<div class="card-face-content">
Front
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-face-inner">
<div class="card-face-content">
<a href="#foo">Back</a>
</div>
</div>
</div>
</div>
</div>
原因是由于 Chrome 中的小精度误差,180 度不完全是半圈。
并且元素的左侧在前面下面(即使你看不到它,它仍然存在)。
在 Z 方向升高你的元素,只是一个像素,并且它起作用了(现在它完全在另一边):
/* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.26, autoprefixer: v9.7.3) */
.card {
-webkit-perspective: 1000px;
perspective: 1000px;
display: inline-block;
}
.card .card-inner {
position: relative;
-webkit-transition: -webkit-transform 0.6s;
transition: -webkit-transform 0.6s;
-o-transition: transform 0.6s;
transition: transform 0.6s;
transition: transform 0.6s, -webkit-transform 0.6s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
}
.card .card-inner .card-face {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card .card-inner .card-face.card-back {
transform: rotateY( 180deg) translateZ(1px); /* changed */
}
.card .card-inner .card-face .card-face-inner .card-face-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 22px;
}
.card:hover .card-inner {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card .card-back {
background: steelblue;
}
<div class="card">
<div class="card-inner">
<img src="https://via.placeholder.com/400x500?text=%20" alt="" />
<div class="card-face card-front">
<div class="card-face-inner">
<div class="card-face-content">
Front
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-face-inner">
<div class="card-face-content">
<a href="#foo">Back</a>
</div>
</div>
</div>
</div>
</div>