gpt4 book ai didi

css - 旋转对象并从顶部缩放

转载 作者:技术小花猫 更新时间:2023-10-29 11:36:25 25 4
gpt4 key购买 nike

我正在尝试通过在 X 位置从上到下旋转来创建悬停时出现的 div,我还想为其旋转添加一些真实感(DIV 的宽度从底部应始终为 100%,但应逐渐从 20% 增加到 100% 白色(它正在旋转)。

enter image description here

.img-event-parent{
position: relative;
}
.img-event-details{
position: absolute;
background-color: rgba(0,0,0,0.8);
left: 0px;
right: 0px;
top: 0px;
height: 100%;
transform: rotateX(90deg);
transform-style: preserve-3d;
-webkit-transform: rotateX(90deg);
transform-origin: bottom;
transition: all 3s;
}
.img-event-parent:hover .img-event-details{
transform: rotateX(0deg);
}
<div class="img-event">
<div class="img-event-parent img-parent">
<a href="#">
<img src="https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350" alt="">
</a>
<div class="img-event-details">
<a href="#" class="slick-desc"><?=$key->post_title?></a>
</div>
</div>
</div>

上面的代码片段旋转了 img-event-details div,但我不知道如何在旋转时仅从顶部调整 div 宽度(如上图所示)。

最佳答案

添加一些 perspective :

.img-event-parent {
position: relative;
display: inline-block;
perspective: 200px; /*Added this*/
perspective-origin: bottom; /*Added this*/
}

.img-event-parent img {
display: block;
}

.img-event-details {
position: absolute;
background-color: rgba(0, 0, 0, 0.8);
left: 0px;
right: 0px;
top: 0px;
height: 100%;
transform: rotateX(90deg);
transform-style: preserve-3d;
transform-origin: bottom;
transition: all 3s;
}

.img-event-parent:hover .img-event-details {
transform: rotateX(0deg);
}
<div class="img-event">
<div class="img-event-parent img-parent">
<a href="#">
<img src="https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=300" alt="">
</a>
<div class="img-event-details">
<a href="#" class="slick-desc">Some text</a>
</div>
</div>
</div>

关于css - 旋转对象并从顶部缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50944367/

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