CSS3 div 悬停时显示删除图标,无 javascript,纯 CSS3

CSS3 div onhover show display delete icon, no javascript, pure CSS3

.img-wrap {
    position: relative;
    display: inline-block;
}
.img-wrap .close {
    position: absolute;
    top: 2px;
    right: 2px;
    z-index: 5;
    transition: opacity 0.15s ease-in;
    padding: 5px 2px 2px;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    opacity: 0;
    text-align: center;
    font-size: 22px;
    line-height: 10px;
    border-radius: 50%;
}
.img-wrap:hover .close {
    z-index: 10;
    background-color: rgb(5 0 0 / 75%);
    opacity: 1;
}
<div class="img-wrap">
    <a href="" class="close float-right red rounded-lg p-2 mr-2 mt-2" title="DELETE"><i class="fas fa-trash-alt fa-lg text-white"></i></a>
    <div class="media">
       <i class="fal fa-file fa-4x icon-pdf d-flex mr-3"></i>
       <div class="media-body">
           <h6 class="mt-0 mb-0 grey-text  font-weight-bold">This is an existing File</h6>
           <div><small><b class="mr-2">File Name</b>
                <a href="" target="_blank">${filename}</a> 
                </small>
          </div>
       </div>
    </div>                          
</div>

☝️这就是我想展示的,结果变成了这样

这适用于图片,但不适用于 div 和文字

只需要在悬停时屏蔽背景。卡在了这个问题上。

如果我理解你的问题,你可以使用 div(我称之为图层)绝对定位在卡片上方,并在你将鼠标悬停在卡片上时显示它。

.img-wrap {
    position: relative;
    display: inline-block;
    width:200px;/* not important */
    height:200px;/* not important */
    background:#aeaeae;/* not important */
}
.img-wrap .close {
    position: absolute;
    top: 2px;
    right: 2px;
    z-index: 5;
    transition: opacity 0.15s ease-in;
    padding: 5px 2px 2px;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    opacity: 0;
    text-align: center;
    font-size: 22px;
    line-height: 10px;
    border-radius: 50%;
}
.img-wrap:hover .close {
    z-index: 10;
    background-color: rgb(5 0 0 / 75%);
    opacity: 1;
}

/* add this */
.layer{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
z-index:2;
background:rgba(255,255,255,0.9);
display:none;
}

.img-wrap:hover .layer{
display:block;
}
<div class="img-wrap">
    <a href="" class="close float-right red rounded-lg p-2 mr-2 mt-2" title="DELETE"><i class="fas fa-trash-alt fa-lg text-white"> x </i></a>
    <div class="layer"> </div>
    <div class="media">
       <i class="fal fa-file fa-4x icon-pdf d-flex mr-3"></i>
       <div class="media-body">
           <h6 class="mt-0 mb-0 grey-text  font-weight-bold">This is an existing File</h6>
           <div><small><b class="mr-2">File Name</b>
                <a href="" target="_blank">${filename}</a> 
                </small>
          </div>
       </div>
    </div>                          
</div>