CSS实现侧边展开导航栏

效果图

在这里插入图片描述

代码

<!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>
        *{
            margin: 0;
            padding: 0;
        }
        input{
            display: none;
        }
        .navbar{
            position: relative;
            width: 100%;
        }
        label img{
            cursor:pointer;
            height: 40px;
            width: 40px;
        }
        label{
            position: absolute;
            display: inline-block;
            width: 100%;
            left: 65px;
            background-color: rgb(224, 224, 224);
            border:1px solid rgb(199, 199, 199);
        }
        .list{
            overflow: hidden;

            top:0;
            list-style: none;
            width: 65px;
            height: 100vh;
            background-color: rgb(0, 56, 121);
        }
        .list li{
            text-decoration: none;
            height: 70px;
            line-height: 70px;
            padding-top: 10px;
            /* margin-top: 10px; */
            /* border: 1px solid yellow; */
        }
        input:checked~ label{
            left: 200px;
        }
        input:checked~.list{
            width: 200px;
        }
        input:checked~ .list li:nth-of-type(1) span{
            display: inherit;
        }
        .list img{
          vertical-align: bottom;
            display: inline-block;
            height: 30px;
            width: 30px;
        }
        .list span{
            font-size: 10px;
            display: inline-block;
            height: 30px;
            line-height: 30px;
            width: 60px;
            color:rgb(221, 221, 221);
            font-size: 4px;
            text-align: left;
        }
        .list a{
            text-decoration: none;
            margin-left: 10px;
            flex-wrap: wrap;
            display: inline-block;
            display: flex;
            height: 65px;
            width: 75% ;
            justify-content: space-around;
            align-content: center;
            /* border:1px solid green; */
        }
        .list li:nth-of-type(1){
            /* border: 1px solid yellow; */
            margin-bottom: 5px;
        }
        .list li:nth-of-type(1) span{
            height: 45px;
            line-height: 45px;
            display: none;
            overflow: hidden;
           width: 60%;

        }
        .list li:nth-of-type(1) img{
            border-radius: 50%;
            height: 45px;
            width: 45px;
        }
        .list li:hover{
            background-color: rgba(0, 33, 80, 0.3);
        }
        input:checked ~ .list span{
            font-size: 14px;
            /* background-color: red; */
        }
    </style>
</head>
<body>
<div class="navbar">
    <input id="checkbox" type="checkbox" />
    <label for="checkbox">
<img src="icons/1.png" />
    </label>
    <ul class="list">
        <li><a href=""><img src="https://i0.hdslb.com/bfs/face/6ab4b703ebd72ad1a73f0a90a002d3cc9f000a6f.jpg@150w_150h.jpg" /><span>管理员你好</span></a></li>
        <li><a href=""><img src="icons/3.png" /><span>工具菜单</span></a></li>
        <li><a href=""><img src="icons/4.png" /><span>商品列表</span></a></li>
        <li><a href=""><img src="icons/5.png" /><span>用户列表</span></a></li>
        <li><a href=""><img src="icons/6.png" /><span>订单列表</span></a></li>
        <li><a href=""><img src="icons/6.png" /><span>功能列表</span></a></li>
    </ul>
</div>
</body>
</html>
  • 3
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值