gpt4 book ai didi

html - 悬停时文本移动

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

我有一个 <div><img>元素在里面,文本在中间。当 <div>悬停在 上,图像的不透明度会发生变化。如果将鼠标悬停在图像上,文本将向左移动一个像素,然后再返回。

.mainimage {
height: 100%;
width: 100%;
background: black;
}

.mainimageimg {
opacity: 0.8;
width: 100%;
height: 100%;
transition: 0.3s;
}

.mainimageimg:hover {
opacity: 1;
}

.mainimageheading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: white;
user-select: none;
font-size: 2.35em;
}
<div class="mainimage">
<img class="mainimageimg" src="https://wallpaper-house.com/data/out/8/wallpaper2you_232687.jpg" draggable="false">
<h1 class="mainimageheading">Text here</h1>
</div>

最佳答案

.mainimage {
height: 100%;
width: 100%;
background: black;
}
.mainimageimg {
opacity:0.8;
width: 100%;
height: 100%;
transition: 0.3s;
}
.mainimage:hover .mainimageimg {
opacity: 1;
}
.mainimage:hover .mainimageheading{
transform: translate(-50%, -50%);
}
.mainimageheading {
position: absolute;
top: 50%;
left: 50%;
text-align: center;
color: white;
user-select: none;
font-size: 2.35em;
transition: 1s all ease;
}

关于html - 悬停时文本移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51367817/

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