3、css3 手写nav导航条(互相学习)

效果例图:

1、首先呈现的是html代码:

html 复制代码
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./3.css">
    <title>Document</title>
</head>
<body>
    <nav class="navbar">
        <ul class="nav-list">
            <li class="nav-item">
                <a href="#" class="nav-link">home</a></li>
            <li class="nav-item">
                <a href="#" class="nav-link">about</a>
                <ul class="dropdown">
                    <li class="dropdown-item"><a href="#" class="dropdown-link">Our Team</a></li>
                    <li class="dropdown-item"><a href="#" class="dropdown-link">Our Story</a></li>
                    <li class="dropdown-item"><a href="#" class="dropdown-link">Careers</a></li>
                </ul>
            </li>
            <li class="nav-item">
                <a href="#" class="nav-link">Services</a>
                <ul class="dropdown">
                    <li class="dropdown-item"><a href="#" class="dropdown-link">web</a></li>
                    <li class="dropdown-item"><a href="#" class="dropdown-link">html</a></li>
                    <li class="dropdown-item"><a href="#" class="dropdown-link">dockewr</a></li>
                    <li class="dropdown-item"><a href="#" class="dropdown-link">nginx</a></li>
                    <li class="dropdown-item"><a href="#" class="dropdown-link">hahah</a></li>
                </ul>
            </li>
            <li class="nav-item">
                <a href="#" class="nav-link">Contact</a>
            </li>
        </ul>
    </nav>
</body>
</html>

2、其次最关键的css3样式代码:

html 复制代码
body{
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}
.navbar{
    background-color: #333;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
}
.nav-list{
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
}
.nav-item{
    position: relative;
}
.nav-link{
    display: block;
    padding: 15px 20px;
    color: white;
    text-decoration: none;
    font-size: 18px;
    transition: background-color 0.3s,transform 0.3s;
    position: relative;
    z-index: 1;
}
.nav-link:hover{
    background-color: #008c8c;
    transform: scale(1.1);
}
.nav-link::after{
    content: "";
    position: absolute;
    left: 50%;
    width: 0;
    height: 3px;
    background-color: #f8f400;
    transition: all 0.4s;
    bottom: 0;
    z-index: 1;
}
.nav-link:hover::after{
    left: 0;
    width: 100%;
}

.dropdown{
    display: none;
    /* height: 0px; */
    position: absolute;
    top: calc(100% + 2px);
    left: -5px;
    background-color: #444;
    list-style: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border-radius: 3px;
    min-width: 150px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    transition: background-color 0.6s ease-in-out;
}
.dropdown-item{
    position: relative;
}
.dropdown-link{
    display: block;
    padding: 15px 20px;
    color: white;
    text-decoration: none;
    font-size: 18px;
    transition: background-color 0.3s;
}
.dropdown-link::after{
    content: "";
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0px;
    height: 2px;
    transition: all 0.4s ease-in-out;
}
.dropdown-link:hover{
    background-color: #008c8c;
}
.dropdown-link:hover::after{
    left: 0;
    width: 100%;
    background-color: #f8f400;
}

.nav-item:hover .dropdown{
    display: block;
    /* height: 300px; */
    opacity: 1;
    transform: translateY(0);
}

总结:CSS太强大了,只是我们现在的学习知识不够,不能够很好的驾驭它,

活到老学到老

相关推荐
忧郁的蛋~18 分钟前
HTML表格导出为Excel文件的实现方案
前端·html·excel
小彭努力中19 分钟前
141.在 Vue 3 中使用 OpenLayers Link 交互:把地图中心点 / 缩放级别 / 旋转角度实时写进 URL,并同步解析显示
前端·javascript·vue.js·交互
然我39 分钟前
别再只用 base64!HTML5 的 Blob 才是二进制处理的王者,面试常考
前端·面试·html
NanLing41 分钟前
【纯前端推理】纯端侧 AI 对象检测:用浏览器就能跑的深度学习模型
前端
呆呆的心43 分钟前
前端必学:从盒模型到定位,一篇搞定页面布局核心 🧩
前端·css
小飞悟43 分钟前
前端高手才知道的秘密:Blob 居然这么强大!
前端·javascript·html
小old弟44 分钟前
用Sass循环实现炫彩文字跑马灯效果
前端
code_YuJun44 分钟前
Promise 基础使用
前端·javascript·promise
Codebee44 分钟前
OneCode自主UI设计体系:架构解析与核心实现
前端·javascript·前端框架
GIS之路1 小时前
GIS 空间关系:九交模型
前端