您的位置:首页 > Web前端 > BootStrap

【一点一滴Bootstrap】导航栏

2016-04-30 21:54 417 查看
        导航栏,是用来展示网页主要信息模块,引导用户了解网站概况并帮助其快速找到搜索目标的一种常用元素。导航栏在一个网页中起到了提纲挈领的作用,现在浏览各大网站,基本都能见到它的存在。所以在我们设计网页的时候,这部分是必不可少且需要多下功夫的地方。

1. 页面效果



2. 实现方式

        以前写导航栏一般都采用iframe的形式,把页面分成几块,左边导航栏,右边页面主题内容……这次换了一种方式,把导航栏做在了页面初始框架中,每次页面先加载这个初始框架,再根据url请求地址的不同加载不同的主体内容并给导航栏添加效果

左边导航栏:

<div class="row hasfixed" style="margin-right:0;" >
<!-- navbar-fixed-top固定到顶头-->
<nav class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<a href="http://baidu.com" target="_blank" class="navbar-brand">
Logo
</a>
</div>
<div class="navbar-header">
<a class="navbar-brand">
User:
</a>
<a href="./index.php?r=user/basicInfo&userCode=<?php echo Yii::app()->user->name; ?>" class="navbar-brand">
<?php echo Yii::app()->user->name; ?>
</a>
<a href="./index.php?r=user/logout" class="navbar-brand">
Logout
</a>
</div>
</nav>
</div>
<div class="row" style="margin:0%;">
<i class="glyphicon glyphicon-th menuDisplay" onclick=menuDisply()></i>
<div class="col-md-2 leftMain">
<i class="glyphicon glyphicon-th menuHide" onclick=menuDisply()></i>
<div class="sidebar-menu leftMenu">
<ul href="#dataMenu" class="nav-header menu-first collapsed" data-toggle="collapse">
<i class="glyphicon glyphicon-align-right menu-first-icon"></i>
Management
</ul>
<ul id="dataMenu" class="nav nav-list collapse menu-second">
<li>
<a href="./index.php?r=management/manageone" <?php if($controllerId== 'manageone')echo "class='activeAuto'"; ?>>
<i class="glyphicon glyphicon-th-list menu-second-icon"></i>
Manage One
</a>
</li>
<li>
<a href="./index.php?r=management/managetwo" <?php if($controllerId== 'managetwo')echo "class='activeAuto'"; ?>>
<i class="glyphicon glyphicon-th-list menu-second-icon"></i>
Manage Two
</a>
</li>
<li>
<a href="./index.php?r=management/managethree" <?php if($controllerId == 'managethree')echo "class='activeAuto'";?> >
<i class="glyphicon glyphicon-cog menu-second-icon"></i>
Manage Three
</a>
</li>
<li>
<a href="./index.php?r=management/managefour" <?php if($controllerId == 'managefour')echo "class='activeAuto'"; ?>>
<i class="glyphicon glyphicon-cog menu-second-icon"></i>
Manage Four
</a>
</li>
</ul>
<ul href="#userMeun" class="nav-header menu-first collapsed" data-toggle="collapse">
<i class="glyphicon glyphicon-cog menu-first-icon"></i>
Administration
</ul>
<ul id="userMeun" class="nav nav-list collapse menu-second">
<li>
<a href="./index.php?r=user/user" <?php if($controllerId== 'user')echo "class='activeAuto'";?> >
<i class="glyphicon glyphicon-user menu-second-icon"></i>
User Management
</a>
</li>
<li>
<a href="./index.php?r=book/book" <?php if($controllerId== 'book')echo "class='activeAuto'";?> >
<i class="glyphicon glyphicon-list-alt menu-second-icon"></i>
Book Management
</a>
</li>
<li>
<a href="./index.php?r=data/data" <?php if($controllerId== 'data')echo "class='activeAuto'";?> >
<i class="glyphicon glyphicon-list-alt menu-second-icon"></i>
Data Management
</a>
</li>
<li>
<a href="./index.php?r=computer/computer" <?php if($controllerId== 'computer')echo "class='activeAuto'";?> >
<i class="glyphicon glyphicon-list-alt menu-second-icon"></i>
Computer Mangement
</a>
</li>
</ul>
<ul href="#repository" class="nav-header menu-first collapsed" data-toggle="collapse">
<i class="glyphicon glyphicon-signal menu-first-icon"></i>
Repository
</ul>
<ul id="repositoryMeun" class="nav nav-list collapse menu-second">
<li>
<a href="./index.php?r=repository/repository" <?php if($actionId== 'repository')echo "class='activeAuto'"; ?>>
<i class="glyphicon glyphicon-cog menu-second-icon"></i>
Repository
</a>
</li>
</ul>
</div>
</div>
右边主体内容
<div class="col-md-10 test">
<div class="block box">
<legend>
<div id="ur_here">
<!-- 定义面包屑-->
<?php if(isset($this->breadcrumbs)):?>
<?php $this->widget('zii.widgets.CBreadcrumbs',array(
'homeLink'=>CHtml::link('Home','./index.php?r=user/user'),
'links'=>$this->breadcrumbs,
'separator'=>' > ',
)); ?>
<?php endif?>
</div>
</legend>
</div>
<?php echo $content; ?>
</div>
</div>
<!-- <div>尾部标注</div>-->主要的css样式
<style>
.navbar {
background: rgba(0, 0, 0, 0) -moz-linear-gradient(center bottom , #106891 0%, #2890B7 100%) repeat scroll 0 0;

}
.list-group-item{
background: rgba(0, 0, 0, 0) -moz-linear-gradient(center bottom , #CBCBCB 0%, #F1F1F1 100%) repeat scroll 0 0;
}
a{
text-decoration: none;
}
.menu-first-icon{
margin-left:3%;margin-right:2%;
}
.menu-second-icon{
margin-left:10%;margin-right:2%;
}
a:focus{ outline:none;}
.table{
background-color:#EFF3F6;
}
body {
color: #000;
font-size: 12px;
font-family: "Helvetica Neue",Helvetica,STheiti,微软雅黑,宋体,Arial,Tahoma,sans-serif,serif;
}
/*左侧菜单*/
.sidebar-menu{
border-right: 1px solid #c4c8cb;
border-bottom: 1px solid #c4c8cb;
}
/*一级菜单*/
.menu-first{
color:#999;
color:grey;
height:45px;
line-height:45px;
background: rgba(0, 0, 0, 0) -moz-linear-gradient(center bottom , #efeff0 0%, #fafafa 100%) repeat scroll 0 0;
/*background-color: #e9e9e9;*/
border-top: 1px solid #efefef;
border-bottom: 1px solid #e1e1e1;
padding: 0;
font-size: 14px;
font-weight: normal;
/*text-align: center;*/
}
/*一级菜单鼠标划过状态*/
.menu-first:hover{
cursor:pointer;
text-decoration: none;
background-color: #d6d4d5;
border-top: 1px solid #b7b7b7;
border-bottom: 1px solid #acacac;
}
/*二级菜单*/
.menu-second li a{
background-color: #f6f6f6;
height:31px;
line-height:31px;
border-top: 1px solid #efefef;
border-bottom: 1px solid #efefef;
font-size: 12px;
/*text-align:center;*/
}
/*二级菜单鼠标划过样式*/
.menu-second li a:hover {
text-decoration: none;
background-color: #66c3ec;
border-top: 1px solid #83ceed;
border-bottom: 1px solid #83ceed;
border-right: 3px solid #f8881c;
border-left: 3px solid #66c3ec;
}
/*二级菜单选中状态*/
.menu-second-selected {
background-color: #66c3ec;
height:31px;
line-height:31px;
border-top: 1px solid #83ceed;
border-bottom: 1px solid #83ceed;
border-right: 3px solid #f8881c;
border-left: 3px solid #66c3ec;
/*text-align:center;*/
}
/*覆盖bootstrap的样式*/
.nav-list,.nav-list li a{
padding: 0px;
margin: 0px;
}
ul{
margin-bottom:0px;
}
.navbar {
border-radius: 0px;
</style>       程序用的是PHP编程语言,Yii框架,所以通过如下方式获取url中包含的controller和view值,在html代码中直接使用这两个变量即可
<?php
$controllerId =$this->id; //controller
$actionId=$this->action->id; //action
?>
        当点击左侧菜单栏的子菜单时,会触发一个跳转链接,链接到相对应的页面中。然后根据目的页面做相应的样式渲染,主要根据$controllerId或$actionId判断所在页面,添加相应的class标识,具体的样式由该class设置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: