gpt4 book ai didi

html - 如何在 div 的右侧制作悬停框?

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

我正在尝试修改 this 代码,所以盒子会滑到盒子的左边。我在想我应该改变类 .overlay right: 0;right: 100%;,但它什么也没做。它应该看起来像这样 enter image description here另外,当我将鼠标悬停在盒子上时,盒子向右滑动时,我的盒子会一直停留,直到我将鼠标移开,我该怎么办?

这是我在右侧制作动画时的 css 代码:

.container {
position: relative;
width: 50%;
}

.image {
display: block;
width: 100%;
height: auto;
}

.overlay {
position: absolute;
bottom: 0;
left: 100%;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 0;
height: 100%;
transition: .5s ease;
}

.container:hover .overlay {
width: 100%;
}

.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}

最佳答案

使用此代码在悬停时向左移动叠加层

.overlay {
position: absolute;
bottom: 0;
left: 0;
background-color: #008CBA;
overflow: hidden;
width: 0;
height: 100%;
transition: .5s ease;
}

.container:hover .overlay {
width: 100%;
left: -100%;
}

.container {
position: relative;
width: 50%;
float:right;
}

.image {
display: block;
width: 100%;
height: auto;
}

.overlay {
position: absolute;
bottom: 0;
left: 0;
background-color: #008CBA;
overflow: hidden;
width: 0;
height: 100%;
transition: .5s ease;
}

.container:hover .overlay {
width: 100%;
left: -100%;
}

.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<h2>Slide in Overlay from the Right</h2>
<p>Hover over the image to see the effect.</p>

<div class="container">
<img src="https://www.w3schools.com/howto/img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>

关于html - 如何在 div 的右侧制作悬停框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44292265/

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