gpt4 book ai didi

html - CSS flip card 在转换完成之前不会显示背面相关的子元素

转载 作者:行者123 更新时间:2023-11-28 19:11:09 25 4
gpt4 key购买 nike

从这里拿翻转卡片的例子: https://www.w3schools.com/howto/howto_css_flip_card.asp

<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img src="img_avatar.png" alt="Avatar" style="width:300px;height:300px;">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>

CSS:

/* The flip card container - set the width and height to whatever you want. We have added the border property to demonstrate that the flip itself goes out of the box on hover (remove perspective if you don't want the 3D effect */
.flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px; /* Remove this if you don't want the 3D effect */
}

/* This container is needed to position the front and back side */
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}

/* Do an horizontal flip when you move the mouse over the flip box container */
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}

/* Position the front and back side */
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}

/* Style the front side (fallback if image is missing) */
.flip-card-front {
background-color: #bbb;
color: black;
}

/* Style the back side */
.flip-card-back {
background-color: dodgerblue;
color: white;
transform: rotateY(180deg);
}

如果我对背面卡片的其中一个子元素进行简单更改以将其相对定位,则在转换完成之前我看不到任何背面卡片元素。

<div class="flip-card-back">
<h1 style="position: relative;">John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>

enter image description here

在我的场景中,我正在创建一个带有第 3 方子元素的翻转卡片,我无法修改这些元素的相对位置。有什么想法吗?

最佳答案

检查这个:https://codepen.io/shahry4r/pen/jOEqyWY

<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
</div>
</div>
</div>


/* entire container, keeps perspective */
.flip-container {
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}

.flip-container, .front, .back {
width: 320px;
height: 480px;
}

/* flip speed goes here */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;

position: relative;
}

/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;

position: absolute;
top: 0;
left: 0;
}

/* front pane, placed above back */
.front {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}

/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
}

例子:

https://davidwalsh.name/css-flip

https://davidwalsh.name/demo/css-flip.php

关于html - CSS flip card 在转换完成之前不会显示背面相关的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59271821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com