gpt4 book ai didi

javascript - 具有可折叠和不可折叠元素的导航栏

转载 作者:行者123 更新时间:2023-11-30 16:43:12 24 4
gpt4 key购买 nike

我需要在 Bootstrap 中创建一个导航栏,它在桌面上显示如下图。 (图 1)

enter image description here

在移动设备上,我希望将其折叠起来,如图 2 草图所示。

enter image description here

为此,我使用了如下代码和 Bootstrap 。

<div>

<nav class="navbar navbar-default navbar-fixed-top">

<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>

</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> My Profile</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Post</a></li>
</ul>
</div>
</div>

</nav>

</div>

当屏幕尺寸缩小时,移动 View 中的图像是我想要的,因此只显示字形。

请让我知道您的想法,因为我是新手。 JsFiddle is here.

最佳答案

这是实现此目的的一种方法的示例:nav 被重组为列,以便说明固定的正确图标。

.wrapper {
padding-left: 15px;
padding-right: 15px;
padding-bottom: 75px;
margin: 0 auto;
}
.wrapper .navbar-default {
border: transparent;
margin: 0px;
padding: 0px;
width: 100%;
border-bottom: 6px solid #266080;
height: 56px;
position: fixed;
border-radius: 0px;
}
.navbar-toggle {
right: 35%;
}
.navbar-collapse {
background: #f5f5f5;
}
.no-gutter >[class*='col-'] {
padding-right: 0;
padding-left: 0;
}
.login {
display: inline;
position: fixed;
width: 100%;
height: 56px;
margin: 0px;
padding: 0px 0px 0px 25px;
border: transparent;
border-radius: 0px;
}
.login .glyphicon {
padding: 10px 5px;
margin: 0 auto;
}
.login p {
display: inline;
padding: 0;
}
.main-content {
padding: 0 50px;
margin: 0 auto;
}
@media (max-width: 768px) {
.login .glyphicon {
padding: 10px 0px;
}
.login {
padding: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="wrapper">
<div class="row no-gutter">
<div class="col-xs-9 col-xs-8">
<nav class="navbar navbar-default">
<!-- 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="#">Brand</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 class="active"><a href="#">Link <span class="sr-only">(current)</span></a>

</li>
<li><a href="#">Link</a>

</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>

<ul class="dropdown-menu">
<li><a href="#">Action</a>

</li>
<li><a href="#">Another action</a>

</li>
<li><a href="#">Something else here</a>

</li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a>

</li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a>

</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<!--end nav-->
</div>
<!--end col9-->
<div class="col-xs-3 col-xs-4">
<div class="login">
<a href="#" class="btn btn-nav"> <span class="glyphicon glyphicon-user"></span>
<p class="hidden-xs">Profile</p>
</a>
<a href="#" class="btn btn-nav"> <span class="glyphicon glyphicon-log-in"></span>
<p class="hidden-xs">Post</p>
</a>
</div>
</div>
<!--end col3-->
</div>
<!--end row-->
</div>
<!--end wrapper-->
<div class="main-content">
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32.
</p>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32.
</p>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32.
</p>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32.
</p>
</div>

关于javascript - 具有可折叠和不可折叠元素的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31628724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com