美文网首页
三十一、综合案例—土豆网鼠标经过显示遮罩

三十一、综合案例—土豆网鼠标经过显示遮罩

作者: honest涛 | 来源:发表于2021-04-20 20:53 被阅读0次

    案例:土豆网鼠标经过显示遮罩

    image.png
    1. 练习元素的显示与隐藏
    2. 练习元素的定位
      核心原理:原先半透明的黑色遮罩看不见,鼠标经过大盒子,就显示出来。
      遮罩的盒子不占有位置,就需要用绝对定位和display配合使用。

    代码

    <!DOCTYPE html>
    <html lang="en">
    <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>
            .tudou {
                position: relative;
                width: 444px;
                height: 320px;
                background-color: pink;
                margin: 30px auto;
            }
    
            .tudou img {
                width: 100%;
                height: 100%;
            }
    
            .mask {
                /* 隐藏遮罩层 */
                display: none;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, .4) url(images/tudou_arr.png) no-repeat center;
            }
    
            /* 当我们鼠标经过了 土豆这个盒子,就让里面遮罩层显示出来 */
            .tudou:hover .mask {
                /* 而是显示元素 */
                display: block;
            }
        </style>
    </head>
    <body>
        <div class="tudou">
            <div class="mask"></div>
            <img src="/images/tudou.jpg" alt="">
        </div>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:三十一、综合案例—土豆网鼠标经过显示遮罩

          本文链接:https://www.haomeiwen.com/subject/gpcolltx.html