您好我正在构建一个显示传感器数据的主页,我不是一个Web开发人员我选择了bootstrap框架来说服设计不那么费力,但是当我打开页面时我无法获得汉堡菜单工作手机,如果我打开桌面上的页面,我想要正常的导航栏,但是当我在手机上打开它时,我只想要汉堡包菜单按钮,按下时应显示导航栏的项目。
这是我的代码:
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<style>
body {
padding-top: 70px;
font-family: "Roboto Slab","Helvetica Neue",Helvetica,Arial,sans-serif;
/* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */
}
.no-border {
border: none;
background-color: white;
outline: none;
cursor: pointer;
}
.color-no-focus {
color: grey;
}
.hover:hover {
color: blue;
}
.white {
color: white;
}
.btn-circle {
width: 70px;
height: 70px;
text-align: center;
padding: 6px 0;
font-size: 12px;
line-height: 1.42;
border-radius: 32px;
float: right;
}
#container1
{
margin-bottom:10px
}
</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- jQuery Version 1.11.1 -->
<!--script src=" vendor/jquery/1.11.1/jquery-1.11.1.js"></script-->
<!-- Bootstrap Core JavaScript -->
<script src="vendor/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/dataDisplay.js"></script>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Access Home Online</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar navbar-default navbar-fixed-top" id="bs-example-navbar-collapse-1">
<ul class="breadcrumb">
<li>
<a class="breadcrumb-item" href="index.htm">Home</a>
</li>
<li>
<a class="breadcrumb-item" href="settings.htm">Settings</a>
</li>
<li>
<a class="breadcrumb-item" href="connected-sites.htm">Sites</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
在移动视图中我不想要上述3个链接。
答案 0 :(得分:0)
汉堡包不起作用的主要问题是因为你有两个navbar
类,你只能在父容器上使用一次。由于您需要面包屑布局,因此最简单的方法是使用两个不同的菜单,一个用于桌面,一个用于移动设备。这不是最好的方法,但是效果很好的方法,如果你有良好的CSS知识和耐心,你可以删除附加菜单并使用媒体查询重新编写CSS来模仿类breadcrumb提供的相同样式。
以下是有效的HTML代码:
<header>
<ul class="breadcrumb">
<li><a class="breadcrumb-item" href="index.htm">Home</a></li>
<li><a class="breadcrumb-item" href="settings.htm">Settings</a></li>
<li><a class="breadcrumb-item" href="connected-sites.htm">Sites</a></li>
</ul>
<nav class="navbar navbar-default navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Access Home Online</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="index.htm">Home</a></li>
<li><a href="settings.htm">Settings</a></li>
<li><a href="connected-sites.htm">Sites</a></li>
</ul>
</div>
</div>
</nav>
</header>
以下是使用此HTML的CSS:
@media(max-width:767px){
header .breadcrumb {
display: none;
}
}
@media(min-width:768px){
header .navbar {
display: none;
}
}
可以看到更新的jsFiddle working online ...测试各种模式调整结果窗口的大小,以模拟不同的设备大小。
3x图标栏类的目的
bootstrap使用3x图标栏跨度的原因是因为汉堡包图标由3行使用CSS组成,对于你在CSS中拥有的每一行:
.navbar-toggle .icon-bar {
display: block;
width: 22px;
height: 2px;
border-radius: 1px;
}
每条线长22px,高2px,边界半径为1px。