gpt4 book ai didi

javascript - 在另一个 html 元素上具有悬停效果的响应式图像叠加

转载 作者:行者123 更新时间:2023-11-28 16:48:48 27 4
gpt4 key购买 nike

第一个问题:当我将鼠标悬停在图像上时会显示文本叠加层,但我希望当我将鼠标悬停在具有“点”类的跨度上时显示叠加层,如何实现?

第二个问题:文本叠加层没有响应,它不适合图像大小,我希望当我调整图像大小时,文本叠加层会随着图像调整大小,我该如何实现?

如果有 javascript、bootstrap、css 或其他答案,我将不胜感激!

演示:http://jsfiddle.net/0qgcn2uu/9/

HTML:

<span class="point"></span>

<div class="caption">
<img src="http://www.blasdale.com/pictures/2007/Hendon/thumbs/IMG_3337.jpg" />
<div class="caption__overlay">
<div class="caption__overlay__content">
<img id="hello" class="caption__media" src="http://localhost/wp-content/themes/twentyfifteen/images/velveti-grid-item-text-1.png">
</a>
</div>
</div>
</div>

CSS:

.caption {
position: relative;
overflow: hidden;
-webkit-transform: translateZ(0);
}
.caption::before {
content:' ';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: transparent;
transition: background .35s ease-out;
}
/* This block of code is working. When i hover on my img, it gets the overlay
.caption:hover::before {
background: rgba(248, 214, 215, .5);
}
*/

/* I want that when i hover on the circle, the image would get this overlay, but this doesn't work */
.point:hover + .caption::before {
background: rgba(248, 214, 215, .5);
}
.point {
position: absolute;
display: block;
height: 25px;
width: 25px;
border-radius: 30px;
background-color: black;
z-index: 1;
}
.caption__overlay {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
padding: 10px;
color: white;
-webkit-transform: translateY(100%);
transform: translateY(100%);
transition: -webkit-transform .35s ease-out;
transition: transform .35s ease-out;
}
.caption:hover .caption__overlay {
-webkit-transform: translateY(0);
transform: translateY(0);
}

最佳答案

要解决第一个问题,您需要更改:

.caption:hover .caption__overlay {

收件人:

.point:hover + .caption .caption__overlay {

第二个问题解决了:

.caption {
display: inline-block;
}

.caption__media{
max-width: 100%;
}

DEMO

关于javascript - 在另一个 html 元素上具有悬停效果的响应式图像叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32849883/

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