Front-end small tip (1): Use css to mask the image and display the content on the mask, and add animation to ease in

renderings

As shown in the figure, when the mouse hovers over the picture, the mask is displayed and the specific content is displayed

insert image description here

all codes

<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
      
      
            width: 500px;
            height: 500px;
            border-radius: 40px;
            overflow: hidden;
            background-color: rgb(216, 135, 135);
            position: relative;
        }

        .img {
      
      
            width: 100%;
            height: 100%;
            border-radius: 30px;
        }

        .mask {
      
      
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            text-align: center;
            vertical-align: auto;
            background: rgba(0, 0, 0, 0.35);
            color: #ffffff;
            opacity: 0;
        }
        
        a:hover .mask{
      
      
            animation: maskframes 700ms ease-in-out forwards;
        }

        @keyframes maskframes {
      
      
            0% {
      
      
                opacity: 0;
            }
            100% {
      
      
                opacity: 1;
            }
        }
    </style>
</head>

<body>
    <div class="box">
        <image class="img"
            src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"></image>
            <a href="#">
                <div class="mask">
                   <h3>A Picture of food</h3>
                </div>
            </a>
    </div>
</body>

</html>

Guess you like

Origin blog.csdn.net/languageStudent/article/details/127622700