css+js实现响应式自适应顶部菜单导航条效果代码

代码语言:html

所属分类:响应式

代码描述:css+js实现响应式自适应顶部菜单导航条效果代码,兼容pc端和手机移动端显示。

代码标签: css js 响应式 自适应 顶部 菜单 导航条

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
<style>
    :root {
    --primary: #F4BD50;
    --background: #191919;
    --navbar-height: 48px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Poppins, sans-serif;
}

.background {
    display: block;
    width: 100vw;
    height: 100vh;
    opacity: 1;
    z-index: 1;
    background-size: cover;
    background-repeat: no-repeat;
}

.menu__wrapper {
    display: flex;
    position: relative;
    flex-direction: row;
    z-index: 2;
}

.menu__bar {
    position: fixed;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
    padding: 0 1rem;
    gap: 2rem;
    background: var(--background);
    height: 4rem;
    opacity: 0.9;

}

.menu-icon {
    cursor: pointer;
    display: flex;
    height: 2rem;
    width: 2rem;
}

.navigation {
    display: flex;
    flex-direction: row;
    list-style-type: none;
    align-items: center;
    gap: 1.5rem;
    padding: 0;
    background-color: var(--background);
}

.logo svg {
    width: 2rem;
    height: 2rem;
}

.navigation>li {
    display: flex;
    position: relative;
    cursor: pointer;
    font-size: 1.25rem;
}

.navigation>li>a {
    color: white;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
    text-decoration: none;
    font-weight: 500;
    background-image: linear-gradient(to right,
            var(--primary),
            var(--primary) 50%,
            white 50%);
    background-size: 200% 100%;
    background-position: -100%;
    display: inline-block;
    padding: 0.2rem 0;
    position: relative;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: all 0.2s ease-in-out;
}

.navigation>li>a:before {
    content: '';
    background: var(--primary);
    display: block;
    position: absolute;
    bottom: -0.125rem;
    left: 0;
    width: 0;
    height: 0.125rem;
    transition: all 0.2s ease-in-out;
}

.navigation>li>a:hover {
    background-position: 0;
}

.navigation>li>a:hover::before {
    width: 100%;
}

@media (min-width: 600px) {
    .menu-icon {
        display: none;
    }
}

@media (max-width: 600px) {

    .navigation {
        display: none;
    }

    .menu-icon {
        display: block;
    }

    .navigation--mobile {
        top: var(--navbar-height);
        position: absolute;
        right: 0;
        display: flex;
        padding: 5rem 3.5rem;
        min-height: 100%;
        background-color: var(--background);
        gap: 0.5rem;
        flex-direction: column;
        align-items: flex-start;
        opacity: 0.95;
        animation: fadein 0.3s forwards;
    }

    @keyframes fadein {
        0% {
            opacity: 0;
            width: 0;
            height: 0;
        }

        100% {
            opacity: 1;
            width: 100%;
            height: calc(100vh - var(--navbar-height));
        }
    }

    .navigation--mobile--fadeout {
        animation: fadeout 300ms forwards;
    }

    @keyframes fadeout {.........完整代码请登录后点击上方下载按钮下载查看

网友评论0