纯CSS实现nav导航栏+jQuery实现article区DIV切换

效果图:

main.html 代码:

  1 <!DOCTYPE html>
  2 <html>
  3 <head>
  4 <title>MyHomepage</title>
  5 <meta charset="utf-8" />
  6 <link type="text/css" rel="stylesheet" href="css/reset.css" />
  7 <link type="text/css" rel="stylesheet" href="css/layout.css" />
  8 <link type="text/css" rel="stylesheet" href="css/style.css" />
  9 <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
 10 <script type="text/javascript">
 11 $(document).ready(function(){
 12       $(‘ul li a‘).click(function() {
 13           var className = $(this).attr(‘class‘);
 14           $(‘article div.‘+className).show().siblings().hide();
 15       });
 16 });
 17 </script>
 18 </head>
 19 <body>
 20     <div class="outer">
 21         <header>
 22             <div>Get busy living or get busy dying </div>
 23         </header>
 24         <nav>
 25             <ul>
 26                 <li>
 27                     <a href="#" class="homepage">首&nbsp;页</a>
 28                 </li>
 29                 <li>
 30                     <a href="#">明&nbsp;星</a>
 31                     <ul>
 32                         <li><a href="#" class="bruceli">李小龙</a></li>
 33                         <li><a href="#" class="jackcheng">成龙</a></li>
 34                     </ul>
 35                 </li>
 36                 <li>
 37                     <a href="#">风景名胜</a>
 38                     <ul>
 39                         <li><a href="#" class="tiananmen">天安门</a></li>
 40                         <li><a href="#" class="dongfangmingzhu">东方明珠</a></li>
 41                         <li><a href="#" class="yulongxueshan">玉龙雪山</a></li>
 42                     </ul>
 43                 </li>
 44                 <li>
 45                     <a href="#">风景名胜</a>
 46                     <ul>
 47
 48                     </ul>
 49                 </li>
 50                 <li>
 51                     <a href="#">风景名胜</a>
 52                     <ul>
 53
 54                     </ul>
 55                 </li>
 56                 <li>
 57                     <a href="#">风景名胜</a>
 58                     <ul>
 59
 60                     </ul>
 61                 </li>
 62                 <li>
 63                     <a href="#">风景名胜</a>
 64                     <ul>
 65
 66                     </ul>
 67                 </li>
 68                 <li>
 69                     <a href="#">风景名胜</a>
 70                     <ul>
 71
 72                     </ul>
 73                 </li>
 74
 75             </ul>
 76         </nav>
 77         <aside>
 78             <div>
 79                 <h2>小导航</h2>
 80                 <ul>
 81                     <li><a href="#" class="guilin">桂林山水甲天下</a></li>
 82                     <li><a href="#" class="guilin">桂林山水甲天下</a></li>
 83                     <li><a href="#" class="guilin">桂林山水甲天下</a></li>
 84                     <li><a href="#" class="guilin">桂林山水甲天下</a></li>
 85                     <li><a href="#" class="guilin">桂林山水甲天下</a></li>
 86                 </ul>
 87             </div>
 88
 89
 90         </aside>
 91         <article >
 92             <div class="homepage">
 93                 首页
 94
 95             </div>
 96             <div class="bruceli">
 97                 李小龙
 98
 99             </div>
100             <div class="jackcheng">
101                 成龙
102
103             </div>
104             <div class="tiananmen">
105                 天安门
106
107             </div>
108             <div class="dongfangmingzhu">
109                 东方明珠
110
111             </div>
112             <div class="yulongxueshan">
113                 玉龙雪山
114
115             </div>
116             <div class="guilin">
117                 桂林米粉
118
119             </div>
120         </article >
121         <footer>
122             I‘m footer
123
124         </footer>
125
126     </div>
127 </body>
128
129 </html>

layout.css 代码:

/* layout.css */
.outer {
    margin: 0 auto;
    width: 80%;
    height: 100%;
    min-width: 1000px;
    /*background: gray;*/
    /*min-height: 600px;*/
}
header {
    width: 100%;
    height: 80px;
    background-color: #663366;
    border-radius: 10px;
}
header div {
    line-height: 80px;
    text-align: center;
    vertical-align: middle;
    font-size: 30px;
    font-weight: bold;
}
nav {
    margin-top: 5px;
    width: 100%;
    height: 50px;
    background-color: #666600;
    border-radius: 10px;
    font-size: 20px;
}
aside {
    float: left;
    margin-top: 5px;
    width: 19%;
    height: 400px;
    background-color: #669900;
}
aside div {
    margin-top: 20px;
    margin-left: 40px;
}
aside div ul {
    margin-top: 10px;
    font-size: 16px;
}
aside div ul li {
    line-height: 30px;
}
aside div ul li a {
    text-decoration: underline;
}
article {
    float: left;
    margin-top: 5px;
    margin-left: 5px;
    width: 80%;
    height: 800px;
}
article div {
    width: 100%;
    height: 800px;
    background-color: #6699CC;
    display: none;
    font-size: 300px;
}
article div{
    display: none;
}
article div.homepage{
    display: block;
}
footer {
    margin-top: 810px;
    width: 100%;
    height: 40px;
    background-color:#9933FF;
}
ul li{
    list-style: none;
}
nav ul li {
    float: left;
    width: 120px;
    padding: 12px 0px;
    text-align: center;
    display: inline-block;
    opacity: 0.9;
    background: #663399;
    border-radius: 10px;
}
nav ul li ul {
    width: 120px;
    margin-top: 12px;
    display: none;
    font-size: 16px;
}
nav ul li ul li{
    width: 100px;
    height: 20px;
    margin-left: 10px;
    border-radius: 10px;
    background-color: #993399;
}
nav ul li:hover ul {
    display: block;
    position: absolute;
    text-decoration: underline;
}
nav ul li:hover a {
    color: #CC99FF;
}
nav ul li ul li a:hover {
    text-decoration: underline;
}

style.css 代码

/* style.css */
body {
    background: url("../image/black-Linen.jpg");
    font-size: 14px;
    font-family: "微软雅黑";
    font-weight: normal;
}

reset.css 代码

/* reset.css */
*,body,div,h1,h2,h3,h4,h5,h6,nav,ul,li,img {
    margin:0;
    padding:0;
}
a {
    text-decoration:none;
}
a:visited {
    color:white;
}

以上。

时间: 2024-08-03 23:36:34

纯CSS实现nav导航栏+jQuery实现article区DIV切换的相关文章

淘宝分类导航条;纯css实现固定导航栏

效果如下: 页面如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="t

纯CSS下拉导航和jquery下拉导航对比

纯css实现的下拉导航demo:http://codepen.io/tianzi77/pen/xGOyxp 不用javascript以及jquery动态效果实现导航条的下拉效果.纯css属性实现,主要应用到绝对定位中的left:auto和left:-9999px:来隐藏或者鼠标经过的时候显示下拉菜单. htm结构: <ul class="nav"> <li><a href="/">小哲</a></li> &

纯css的二级导航栏

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <div id="container"> <ul class="nav clearfix"> <li> <a href=#>首

【源码分享】jquery+css实现侧边导航栏

jquery+css实现侧边导航栏 最近做项目的时候,突然想用一个侧边导航栏,网上找了几个插件,有的太丑而且不太符合我的预期.与其修改别人的代码,不如自己来写一个了.废话不多说先上图,感兴趣的请继续看下去. 1效果图 当有顶部导航栏的时候侧边导航栏会消失. 响应式方面,同样的顶部导航栏消失后右下角的图标才出现.点击出现导航,选中后消失: 这里是个demo ,没有做平滑滚动,需要的可以自己加上. 大体就介绍这么多吧,下面上代码. 2css代码 这里是css代码,详情请看注释 1 <style>

如何使用纯CSS制作特效导航条?

先上张图,如何使用纯 CSS 制作如下效果? 在继续阅读下文之前,你可以先缓一缓.尝试思考一下上面的效果或者动手尝试一下,不借助 JS ,能否巧妙的实现上述效果. OK,继续.这个效果是我在业务开发的过程中遇到的一个类似的小问题.其实即便让我借助 Javascript ,我的第一反应也是,感觉很麻烦啊.所以我一直在想,有没有可能只使用 CSS 完成这个效果呢? 定义需求 我们定义一下简单的规则,要求如下: <ul> <li>不可思议的CSS</li> <li>

css小案例:导航栏特效

css小案例:导航栏特效,实现如下图所示效果: 首先可以将html代码写出: 1 <nav class="cl-effect-1"> 2 <a href="#">Umbrella</a> 3 <a href="#">Ineffable</a> 4 <a href="#">Lilt</a> 5 <a href="#"&g

纯CSS实现二级导航下拉菜单--css的简单应用

思想:使用css的display属性控制二级下拉菜单的显示与否.当鼠标移动到一级导航菜单的li标签时,显示二级导航菜单的ul标签.由于实现起来比较简单,所以在这里直接给出了参考代码. 1.纯CSS二级导航下拉菜单代码: 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8" content="text/html" http

纯CSS制作二级导航

原文:纯CSS制作二级导航 一.问题描述 做一个类似校园网首页,主要是导航栏的设置,ul默认纵向排列,如何横向排列,同时去掉圆点. 二.问题解决 2.1 先写导航条 用两个ul嵌套,一个ul是横向导航条,另一个是每个小项目下连一个竖向的ul. 1 <ul id="nav_ul"> 2 <li> 3 <a href="#">首页</a> 4 <ul class="nav_ul_ul"> 5

NAV导航栏———下拉菜单

利用CSS实现导航栏菜单—下拉菜单. 首先给出HTML下拉菜单布局格式: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Stylin' with CSS - Figure 6.5 Drop-Down Menus</title> <link rel="stylesheet" type="text/css&