响应式全屏导航

响应式全屏导航

每天一个小案例

HTML部分

<header>
        <main>
            <div class="logo">小神童</div>
            <ul class="nav">
                <li><a href="#">首页</a></li>
                <li><a href="#">关于我</a></li>
                <li><a href="#">我的作品</a></li>
                <li><a href="#">我的简历</a></li>
                <li><a href="#">我的博客</a></li>
            </ul>
            <!-- 三条线折叠按钮 -->
            <div class="burger">
                <div class="top-line"></div>
                <div class="mid-line"></div>
                <div class="bottom-line"></div>
            </div>
        </main>
    </header>

CSS部分

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

header {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: url(../img/flower.jpg);
    background-size: cover;
    /*图片自动缩放 */
}

main {
    display: flex;
    align-items: center;
    height: 80px;
    padding: 0 5vw;
    background-color: rgba(24, 30, 37, 0.9);
}

.logo {
    font-size: 24px;
    color: #dadbdd;
    font-weight: 600;
    flex: 1;
}

.nav {
    flex: 1;
    display: flex;
    justify-content: space-between;
    max-width: 520px;
}

.nav li {
    list-style: none;
    /* flex: 20%; */
    font-weight: 600;
}

a {
    text-decoration: none;
    color: #dadbdd;
}

.burger div {
    width: 25px;
    height: 3px;
    background-color: #dadbdd;
    margin: 4px;
}

.burger {
    display: none;
}

@media screen and (max-width:760px) {
    .nav {
        position: absolute;
        top: 80px;
        right: 0;
        bottom: 0;
        width: 50vw;
        /* 浏览器高度减去它top */
        height: calc(100vh - 80px);
        background-color: rgba(24, 30, 37, 0.9);
        flex-direction: column;
        align-items: center;
        justify-content: start;
        /* 开始时隐藏,出来时有过渡效果 */
        transform: translateX(100%);
        transition: 0.4s ease-in-out;
    }
    .nav.open {
        transform: translateX(0);
    }
    .nav li {
        margin: 3vh;
        /* transform: translateX(20px); */
        /* 透明度为0 */
        /* opacity: 0; */
    }
    .burger {
        display: block;
    }
    /* 三个条的过渡效果 */
    .burger.active div {
        transition: 0.3s ease-in-out 0.3s;
    }
    .burger.active .top-line {
        transform: rotate(45deg) translate(4px, 6px);
    }
    .burger.active .bottom-line {
        transform: rotate(-45deg) translate(4px, -6px);
    }
    .burger.active .mid-line {
        opacity: 0;
        transform: translateX(10px);
        transition: 0.3s ease-in-out;
    }
    /* 动画 li一个接一个出来 */
    /* @keyframes slideIn {
        /* 开始 
        from {
            transform: translateX(20px);
            /* 透明度为0 
            opacity: 0;
        }
        /* 结束 
        to {
            transform: translateX(0);
            opacity: 1;
        }
    } */
}

js部分

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

header {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: url(../img/flower.jpg);
    background-size: cover;
    /*图片自动缩放 */
}

main {
    display: flex;
    align-items: center;
    height: 80px;
    padding: 0 5vw;
    background-color: rgba(24, 30, 37, 0.9);
}

.logo {
    font-size: 24px;
    color: #dadbdd;
    font-weight: 600;
    flex: 1;
}

.nav {
    flex: 1;
    display: flex;
    justify-content: space-between;
    max-width: 520px;
}

.nav li {
    list-style: none;
    /* flex: 20%; */
    font-weight: 600;
}

a {
    text-decoration: none;
    color: #dadbdd;
}

.burger div {
    width: 25px;
    height: 3px;
    background-color: #dadbdd;
    margin: 4px;
}

.burger {
    display: none;
}

@media screen and (max-width:760px) {
    .nav {
        position: absolute;
        top: 80px;
        right: 0;
        bottom: 0;
        width: 50vw;
        /* 浏览器高度减去它top */
        height: calc(100vh - 80px);
        background-color: rgba(24, 30, 37, 0.9);
        flex-direction: column;
        align-items: center;
        justify-content: start;
        /* 开始时隐藏,出来时有过渡效果 */
        transform: translateX(100%);
        transition: 0.4s ease-in-out;
    }
    .nav.open {
        transform: translateX(0);
    }
    .nav li {
        margin: 3vh;
    }
    .burger {
        display: block;
    }
    /* 三个条的过渡效果 */
    .burger.active div {
        transition: 0.3s ease-in-out 0.3s;
    }
    .burger.active .top-line {
        transform: rotate(45deg) translate(4px, 6px);
    }
    .burger.active .bottom-line {
        transform: rotate(-45deg) translate(4px, -6px);
    }
    .burger.active .mid-line {
        opacity: 0;
        transform: translateX(10px);
        transition: 0.3s ease-in-out;
    }

}

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值