百叶窗效果 html+css

这是我参与更文挑战的第22天

效果:

1
大家好,今天分享一个百叶窗css效果,其实实现很简单,打开vscode,一起冲冲冲~

实现:

1.定义父盒子,放入5张图片:

 <ul>
        <li><img src="1.jpg" alt=""><div>Night</div></li>
        <li><img src="2.jpg" alt=""><div>Night</div></li>
        <li><img src="4.jpg" alt=""><div>Night</div></li>
        <li><img src="3.jpg" alt=""><div>Night</div></li>
        <li><img src="5.jpg" alt=""><div>Night</div></li>
    </ul>
复制代码

2.给父亲元素宽,高:

 ul{
            width: 550px;
            height: 300px;
            overflow: hidden;
            cursor: pointer;
        }
复制代码

cursor: pointer;改变鼠标样式为小手。

3.li先默认宽110px:

 li{
            float: left;
            width: 110px;
            height: 300px;
            list-style: none;
            transition: all 1s;
            position: relative;
        }
复制代码
  img{
            height: 100%;
            width: 450px;
            
        }
复制代码

transition 过渡效果

4.图片下面那个文字通过定义伪类元素定位上去

双伪类元素

 li::after{
            content: 'Night';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 450px;
            height: 30px;
            line-height: 30px;
            font-size: 16px;
            text-align: center;
            color: rgb(243, 230, 230);
            background-color: rgba(48, 46, 46,.5);
        }
复制代码

5.鼠标经过的li变450px宽,其它li显示25px宽:

 ul:hover li{
            width: 25px;
        }
        ul li:hover{
            width: 450px;
        }
       
复制代码

到这里就实现啦~ 完整源码如下,可直接复制运行查看效果:

完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-image: radial-gradient(white,black);
        }
        ul{
            width: 550px;
            height: 300px;
            overflow: hidden;
            cursor: pointer;
        }
        li{
            float: left;
            width: 110px;
            height: 300px;
            list-style: none;
            transition: all 1s;
            position: relative;
        }
       li::after{
            content: 'Night';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 450px;
            height: 30px;
            line-height: 30px;
            font-size: 16px;
            text-align: center;
            color: rgb(243, 230, 230);
            background-color: rgba(48, 46, 46,.5);
        }
        img{
            height: 100%;
            width: 450px;
            
        }
        ul:hover li{
            width: 25px;
        }
        ul li:hover{
            width: 450px;
        }
       
    </style>
</head>
<body>
    
    <ul>
        <li><img src="1.jpg" alt=""><div>Night</div></li>
        <li><img src="2.jpg" alt=""><div>Night</div></li>
        <li><img src="4.jpg" alt=""><div>Night</div></li>
        <li><img src="3.jpg" alt=""><div>Night</div></li>
        <li><img src="5.jpg" alt=""><div>Night</div></li>
    </ul>

</body>
</html>
复制代码

下次见啦,关注我,看更多简单但创意十足的css创意特效。

Snipaste_2021-06-24_20-08-02.png

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享