首页
/ SideNavigation 项目教程

SideNavigation 项目教程

2024-08-19 04:14:29作者:袁立春Spencer

1. 项目的目录结构及介绍

SideNavigation 项目的目录结构如下:

SideNavigation/
├── css/
│   └── style.css
├── js/
│   └── script.js
├── index.html
└── README.md

目录介绍

  • css/: 包含项目的样式文件 style.css
  • js/: 包含项目的脚本文件 script.js
  • index.html: 项目的入口文件。
  • README.md: 项目的说明文档。

2. 项目的启动文件介绍

项目的启动文件是 index.html。这个文件包含了页面的基本结构和引入的 CSS 及 JavaScript 文件。

index.html 内容概览

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/style.css">
    <title>Side Navigation</title>
</head>
<body>
    <div id="mySidenav" class="sidenav">
        <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
        <a href="#">About</a>
        <a href="#">Services</a>
        <a href="#">Clients</a>
        <a href="#">Contact</a>
    </div>
    <span onclick="openNav()">open</span>
    <div id="main">
        <!-- 页面内容 -->
    </div>
    <script src="js/script.js"></script>
</body>
</html>

关键部分解释

  • <div id="mySidenav" class="sidenav">: 侧边导航栏的容器。
  • <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>: 关闭侧边导航栏的按钮。
  • <span onclick="openNav()">open</span>: 打开侧边导航栏的按钮。
  • <div id="main">: 主页面内容容器。

3. 项目的配置文件介绍

项目的配置文件主要是 css/style.cssjs/script.js

css/style.css

这个文件包含了侧边导航栏的样式定义。

/* The side navigation menu */
.sidenav {
    height: 100%; /* 100% Full-height */
    width: 0; /* 0 width - change this with JavaScript */
    position: fixed; /* Stay in place */
    z-index: 1; /* Stay on top */
    top: 0; /* Stay at the top */
    left: 0;
    background-color: #111; /* Black*/
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 60px; /* Place content 60px from the top */
    transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
}

/* The navigation menu links */
.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #818181;
    display: block;
    transition: 0.3s;
}

/* When you mouse over the navigation links, change their color */
.sidenav a:hover {
    color: #f1f1f1;
}

/* Position and style the close button (top right corner) */
.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
    transition: margin-left .5s;
    padding: 20px;
}

/* On smaller screens, where height is less than 
登录后查看全文
热门项目推荐