gpt4 book ai didi

css - 鼠标悬停 Div 尺寸问题

转载 作者:行者123 更新时间:2023-11-28 12:40:35 25 4
gpt4 key购买 nike

我目前正在处理一个网站的部分,其中有一个图像网格。我正在尝试设置它,以便当您将鼠标悬停在图像上时,会出现另一个带有一些不透明背景和文本的 div。问题是我无法让鼠标悬停 div 匹配父级的相同尺寸。到目前为止,它在两个方向上都很粘。有什么建议么?这是一些代码

<div class = 'picture-container'>
<div class = 'picture-wrapper' id = 'top-left'>
<div class = 'onhover'>hello!</div>
<img src = 'ds-map.png' height = '100%' width = '100%'>
</div>
<div class = 'picture-wrapper' id = 'top-right'>
<div class = 'onhover'>hello!</div>
<img src = 'ds-map.png' height = '100%' width = '100%'>
</div>
<div class = 'picture-wrapper' id = 'top-center'>
<div class = 'onhover'>hello!</div>
<img src = 'ds-map.png' height = '100%' width = '100%'>
</div>
</div>

.onhover{
position:absolute;
display:none;
width:30%;
height:100%;
background-color:#F5D892;
opacity:.4;
}


.picture-wrapper{
width:30%;
height:100%;
}

.picture-wrapper:hover .onhover{
display:block;
}

最佳答案

这是一个jsFiddle

<div class='picture-container'>
<div class='picture-wrapper' id='top-left'>
<div class='onhover'>hello!</div>
<div class="img"> </div>
</div>
<div class='picture-wrapper' id='top-right'>
<div class='onhover'>hello!</div>
<div class="img"> </div>
</div>
<div class='picture-wrapper' id='top-center'>
<div class='onhover'>hello!</div>
<div class="img"> </div>
</div>
</div>

.onhover {
position:absolute;
display:none;
width:100px;
height:100px;
line-height:100px;
text-align:center;
background-color:#F5D892;
opacity:.4;
}
.picture-wrapper {
width:100%;
height:100%;
}
.picture-wrapper:hover .onhover {
display:block;
}
.img
{
height:100px;
width:100px;
background:blue;
}

看看你的想法

关于css - 鼠标悬停 Div 尺寸问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17681231/

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