自适应导航栏

<!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">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_2443051_erm4fc6b5a.css">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style-type: none;
        }

        .box {
            width: 100px;
            height: 100px;
            overflow: hidden;
            overflow-x: auto;
            display: flex;
        }

        .box ul {
            display: flex;
            flex-direction: column;
            flex-wrap: wrap;
            justify-content: space-around;

        }

        .box li {
            /* display: flex; */
            /* width: 100px; */
            height: 20px;
            line-height: 20px;
            margin-left: 12px;
            /* margin: 0 9px; */
            background-color: royalblue;
        }

        header {
            width: 100%;
            background-color: red;
            display: flex;
            justify-content: space-between;
            align-items: center;

        }

        .logo_icon {
            display: none;
        }

        .menu ul {
            display: flex;
            /* flex-direction:column */
        }

        .menu ul li {
            margin: 0 10px;
        }

        .logo {
            flex: 1;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        @media screen and (max-width:1366px) {
            header {
                background-color: yellowgreen;
            }

            header {
                flex-direction: column;
            }

            .logo {
                display: flex;
                width: 100%;
                align-items: flex-start
            }

            .menu {
                width: 100%;
                text-align: left;
                transition: all .5s;
            }

            .menu ul {
                display: flex;
                flex-direction: column;
            }

            .menu ul li {
                margin: 0;
            }

            .logo_icon {
                display: block;
            }

            input[type='checkbox'] {
                cursor: pointer;
                position: relative;
                width: 13px;
                height: 13px;
                font-size: 13px;
                margin-right: 5px;
                background-color: red;
                display: none;
            }

            .choose_img {
                font-size: 25px;
            }

        }
    </style>
</head>

<body>
    <header>
        <div class="logo">
            <div class="logo_img">logo</div>
            <div class="logo_icon">
                <label for="choose">
                    <i class="choose_img iconfont icon-zhankai"></i>
                    <input type="checkbox" id="choose">
                </label>
            </div>
        </div>
        <div class="menu">

            <ul>
                <li>我们</li>
                <li>中心</li>
                <li>退出</li>
            </ul>
        </div>

    </header>
    <script>
        window.onload = function () {
            let choose = document.getElementById("choose")
            let choose_img = document.getElementsByClassName("choose_img")[0]
            let menu = document.querySelector(".menu")
            choose.addEventListener('change', function () {
                menu.style.display = choose.checked ? 'none' : 'block'
                choose_img.className = choose.checked ? 'choose_img iconfont icon-shouqi' :
                    'choose_img iconfont icon-zhankai';
            })
        }
    </script>
</body>

</html>

也可以直接通过css样式,checkbox是否选中来控制显示和隐藏,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值