cssbootstrap-4responsive-designonhover

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 onhover show delete icon

☝️This is what I want to display, but ended up like this👇

This works for the image but not for div with text

enter image description here

Just need to mask the background on hover. Got stuck over this.


Solution

  • If i understand your problem you can use a div (i called it layer) absolute positioned above the card and show it when you hover the card.

    .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>