css-遮罩层效果

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        @font-face {
            font-family: 'icomoon';
            src: url('fonts/icomoon.eot?418klf');
            src: url('fonts/icomoon.eot?418klf#iefix') format('embedded-opentype'),
            url('fonts/icomoon.ttf?418klf') format('truetype'),
            url('fonts/icomoon.woff?418klf') format('woff'),
            url('fonts/icomoon.svg?418klf#icomoon') format('svg');
            font-weight: normal;
            font-style: normal;
            font-display: block;
        }

        .td {
            position: relative;
            width: 300px;
            height: 200px;
            margin: 0 auto;
        }

        .td img {
            width: 100%;
            height: 100%;
        }

        .td::before {
            font-family: 'icomoon';
            text-align: center;
            line-height: 200px;
            content: '\e912';
            position: absolute;
            font-size: 30px;
            color: #fff;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, .4);
            display: none;
        }

        .td:hover::before {
            display: block;
        }
    </style>
</head>

<body>
    <div class="td">
        <img src="./imgs/002.gif" alt="">
    </div>
</body>

</html>
posted @ 2025-09-24 09:30  紫川先生  阅读(6)  评论(0)    收藏  举报