gpt4 book ai didi

悬停文本上的 CSS 消失而不是像图像那样滑出

转载 作者:太空宇宙 更新时间:2023-11-04 01:25:50 27 4
gpt4 key购买 nike

有人能解释一下为什么当您将鼠标悬停时图像会很好地向后滑动并且文本会立即消失吗?

.wrapper {
position: relative;
overflow: hidden;
width: 100px;
height: 100px;
border: 1px solid black;
}

#image {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: blue;
transition: 1s;
}

.wrapper:hover #image {
transition: 1s;
left: -100px;
}

.wrapper:hover .text {
transition: 1s;
left: 50%;
}

.text {
white-space: nowrap;
//color: black;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 150%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="wrapper">
<img id="image" src="http://lorempixel.com/output/cats-q-c-100-100-4.jpg" />
<div class="text">text</div>
</div>

所以我想要的是文本在悬停时也能很好地滑出,而不仅仅是消失。

最佳答案

您还需要将transition 属性添加到.text:

.wrapper {
position: relative;
overflow: hidden;
width: 100px;
height: 100px;
border: 1px solid black;
}

#image {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: blue;
transition: 1s;
}

.wrapper:hover #image {
transition: 1s;
left: -100px;
}

.wrapper:hover .text {
transition: 1s;
left: 50%;
}

.text {
white-space: nowrap;
//color: black;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 150%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transition: 1s;
}
<div class="wrapper">
<img id="image" src="http://lorempixel.com/output/cats-q-c-100-100-4.jpg" alt="">
<div class="text">text</div>
</div>

关于悬停文本上的 CSS 消失而不是像图像那样滑出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48140404/

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