gpt4 book ai didi

html - 在没有绝对定位的情况下创建具有正面/背面的卡片脚蹼

转载 作者:搜寻专家 更新时间:2023-10-31 22:39:36 25 4
gpt4 key购买 nike

我想向我的网站添加一项新功能,该功能使用来自 David Walsh 网站的 card-flipper 模式:https://davidwalsh.name/css-flip .问题是,我的卡片中的内容是可变的,所以高度是未知的(而且它也是一个响应式网站)。我的页面底部有一个页脚,它需要位于该区域下方,但由于这种方法依赖于绝对定位,因此页脚将位于顶部,如代码笔中所示:https://codepen.io/anon/pen/ALJmGZ

谁能想出任何 css hack 或对这种方法的更改,从而使卡片不必绝对定位?

HTML:

<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front">
<span class="name">David Walsh</span>
</div>
<div class="back">
<div class="back-logo"></div>
<div class="back-title">@davidwalshblog</div>
<p>Mozilla Web Developer, MooTools & jQuery Consultant, MooTools Core Developer, Javascript Fanatic, CSS Tinkerer, PHP Hacker, and web lover.</p>
</div>
</div>
<footer>Here is my footer</footer>
</div>

CSS:

.flip-container {
-webkit-perspective: 1000;
-moz-perspective: 1000;
-o-perspective: 1000;
perspective: 1000;

border: 1px solid #ccc;
}

.flip-container:hover .flipper,
.flip-container.hover .flipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}

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

.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;

-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;

-o-transition: 0.6s;
-o-transform-style: preserve-3d;

transition: 0.6s;
transform-style: preserve-3d;

position: relative;
}

.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;

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

.front {
background: url(http://davidwalsh.name/demo/dwflip.jpg) 0 0 no-repeat;
z-index: 2;
}

.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);

background: #f8f8f8;
}

.front .name {
font-size: 2em;
display: inline-block;
background: rgba(33, 33, 33, 0.9);
color: #f8f8f8;
font-family: Courier;
padding: 5px 10px;
border-radius: 5px;
bottom: 60px;
left: 25%;
position: absolute;
text-shadow: 0.1em 0.1em 0.05em #333;

-webkit-transform: rotate(-20deg);
-moz-transform: rotate(-20deg);
-o-transform: rotate(-20deg);
transform: rotate(-20deg);
}

.back-logo {
position: absolute;
top: 40px;
left: 90px;
width: 160px;
height: 117px;
background: url(http://davidwalsh.name/demo/logo.png) 0 0 no-repeat;
}

.back-title {
font-weight: bold;
color: #00304a;
position: absolute;
top: 180px;
left: 0;
right: 0;
text-align: center;
text-shadow: 0.1em 0.1em 0.05em #acd7e5;
font-family: Courier;
font-size: 2em;
}

.back p {
position: absolute;
bottom: 40px;
left: 0;
right: 0;
text-align: center;
padding: 0 20px;
font-family: arial;
line-height: 2em;
}

footer {
background:red;
}

最佳答案

我找到了一种使用纯 CSS 而不使用绝对位置来完成此操作的方法。我使用了 css 动画而不是过渡,你可以在 50% 关键帧将元素的高度/宽度设置为 0。查看 fiddle :https://codepen.io/anon/pen/bwmkAo

萨斯:

@keyframes no-show {
0% {
transform: rotateY(0deg);
height: auto;
width: 100%;
}

49% {
height: auto;
width: 100%;
}

50% {
height: 0;
width: 0;
}

100% {
transform: rotateY(180deg);
height: 0;
width: 0;
}
}

@keyframes show {
0% {
transform: rotateY(-180deg);
height: 0;
width: 0;
}

49% {
height: 0;
width: 0;
}

50% {
height: auto;
width: 100%;
}

100% {
transform: rotateY(0deg);
height: auto;
width: 100%;
}
}

.flip-container {
border: 1px solid #ccc;
}

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

.flipper {
position: relative;
}

.front, .back {
position: relative;
perspective: 1000px;

transform-style: preserve-3d;
perspective-origin: top center;
animation-duration: 2s;
animation-timing-function: linear;
transition-property: transform;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
overflow: hidden;
}

.front {
z-index: 2;

transform: rotateY(0deg);
animation-name: show;
.flipper.active & {
animation-name: no-show;
}

.inner {
height: 300px;
background: green;
}
}

.back {
transform: rotateY(-180deg);
animation-name: no-show;

.flipper.active & {
animation-name: show;
}

.inner {
height: 400px;
background: blue;
}
}

footer {
background: red;
}

关于html - 在没有绝对定位的情况下创建具有正面/背面的卡片脚蹼,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40119354/

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