gpt4 book ai didi

css - Bootstrap 导航栏折叠对齐

转载 作者:行者123 更新时间:2023-11-28 10:01:30 28 4
gpt4 key购买 nike

我在使用 Bootstrap3 构建导航栏时遇到问题。

这是我未折叠时的导航栏:

enter image description here

这是折叠时的状态(视口(viewport)小于 1000 像素):

enter image description here

我想把所有元素堆叠起来,例如:

  • Gassero/-11.8810(在他的右边)
  • 普通
  • 帕尼埃
  • 继续
  • [img]再见

这是一个 bootply代码:

这是我的导航代码:

<nav class="userbar" role="navigation">
<div class="logo">
<img src="img/befair.png" alt="..." class="imglogo">
</div>

<!-- Brand and toggle get grouped for better mobile display -->
<div class="navhead">

<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>
<div class="brandname">GASISTAFELICE</div>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<div class="navbar-left">
<ul ng-controller="gas_controller" class="optionlist nav navbar-nav">
<li ng-repeat="gasname in gasnames"
ng-class="{ 'active': $index == selectedIndex }"
ng-click="itemClicked($index)">
<a href="#/{{peID}}/" ng-click="getID(gasname.id);">
{{gasname.name}}
</a>
<div class="gaslabel">{{gasname.balance}}&#8364;</div>
</li>
</ul>
<ul class="optionlist nav navbar-nav" ng-controller="menu_controller">
<li markable>
<a href="#/{{peID}}/">
<i class="fa fa-book"></i>Ordinare
</a>
</li>

<li markable>
<a href="#/{{peID}}/paniere">
<i class="fa fa-shopping-cart"></i>Paniere
</a>
</li>
<li markable>
<a href="#/{{peID}}/conto">
<i class="fa fa-user"></i>Conto
</a>
</li>
</ul>

</div>
<div class="navbar-right">
<a class="navpic" href="#/{{peID}}/scheda"><img src="img/user_pic.png" alt="..." class="imgpic"></a>
<a class="titlenav" href="#/{{peID}}/scheda">Ciao {{name}}</a>
</div>

</div><!-- /.navbar-collapse -->
</nav>

这是我的 LESS/CSS:

.userbar {
position: relative;
min-height: 50px;
margin-bottom: 20px;
border: 1px solid transparent;
background-color: #f8f8f8;
border-color: #e7e7e7;
}
.userbar:before,
.userbar:after {
content: " ";
display: table;
}
.userbar:after {
clear: both;
}
.userbar:before,
.userbar:after {
content: " ";
display: table;
}
.userbar:after {
clear: both;
}
@media (min-width: 1000px) {
.userbar {
border-radius: 4px;
}
}
.userbar .navbar-brand {
color: #777777;
}
.userbar .navbar-brand:hover,
.userbar .navbar-brand:focus {
color: #5e5e5e;
background-color: transparent;
}
.userbar .navbar-text {
color: #777777;
}
.userbar .navbar-nav > li > a {
color: #777777;
}
.userbar .navbar-nav > li > a:hover,
.userbar .navbar-nav > li > a:focus {
color: #333333;
background-color: transparent;
}
.userbar .navbar-nav > .active > a,
.userbar .navbar-nav > .active > a:hover,
.userbar .navbar-nav > .active > a:focus {
color: #555555;
background-color: #e7e7e7;
}
.userbar .navbar-nav > .disabled > a,
.userbar .navbar-nav > .disabled > a:hover,
.userbar .navbar-nav > .disabled > a:focus {
color: #cccccc;
background-color: transparent;
}
.userbar .navbar-toggle {
border-color: #dddddd;
}
.userbar .navbar-toggle:hover,
.userbar .navbar-toggle:focus {
background-color: #dddddd;
}
.userbar .navbar-toggle .icon-bar {
background-color: #cccccc;
}
.userbar .navbar-collapse,
.userbar .navbar-form {
border-color: #e7e7e7;
}
.userbar .navbar-nav > .open > a,
.userbar .navbar-nav > .open > a:hover,
.userbar .navbar-nav > .open > a:focus {
background-color: #e7e7e7;
color: #555555;
}
@media (max-width: 999px) {
.userbar .navbar-nav .open .dropdown-menu > li > a {
color: #777777;
}
.userbar .navbar-nav .open .dropdown-menu > li > a:hover,
.userbar .navbar-nav .open .dropdown-menu > li > a:focus {
color: #333333;
background-color: transparent;
}
.userbar .navbar-nav .open .dropdown-menu > .active > a,
.userbar .navbar-nav .open .dropdown-menu > .active > a:hover,
.userbar .navbar-nav .open .dropdown-menu > .active > a:focus {
color: #555555;
background-color: #e7e7e7;
}
.userbar .navbar-nav .open .dropdown-menu > .disabled > a,
.userbar .navbar-nav .open .dropdown-menu > .disabled > a:hover,
.userbar .navbar-nav .open .dropdown-menu > .disabled > a:focus {
color: #cccccc;
background-color: transparent;
}
}
.userbar .navbar-link {
color: #777777;
}
.userbar .navbar-link:hover {
color: #333333;
}
.navhead:before,
.navhead:after {
content: " ";
display: table;
}
.navhead:after {
clear: both;
}
.navhead:before,
.navhead:after {
content: " ";
display: table;
}
.navhead:after {
clear: both;
}
@media (min-width: 1000px) {
.navhead {
float: left;
}
}
.titlenav {
float: left;
padding: 15px 15px;
font-size: 18px;
line-height: 20px;
}
.titlenav:hover,
.titlenav:focus {
text-decoration: none;
}
@media (min-width: 1000px) {
.navbar > .container .titlenav {
margin-left: -15px;
}
}
.collapsebar {
display: none;
max-height: 340px;
overflow-x: visible;
padding-right: 15px;
padding-left: 15px;
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
-webkit-overflow-scrolling: touch;
}
.collapsebar.in {
display: block;
}
.collapsebar:before,
.collapsebar:after {
content: " ";
display: table;
}
.collapsebar:after {
clear: both;
}
.collapsebar:before,
.collapsebar:after {
content: " ";
display: table;
}
.collapsebar:after {
clear: both;
}
.collapsebar.in {
overflow-y: auto;
}
@media (min-width: 1000px) {
.collapsebar {
width: auto;
border-top: 0;
box-shadow: none;
}
.collapsebar.collapse {
display: block !important;
height: auto !important;
padding-bottom: 0;
overflow: visible !important;
}
.collapsebar.in {
overflow-y: visible;
}
.navbar-fixed-top .collapsebar,
.navbar-static-top .collapsebar,
.navbar-fixed-bottom .collapsebar {
padding-left: 0;
padding-right: 0;
}
}

@media (min-width: 1000px) {
.navbar-left {
float: left !important;
}
.navbar-right {
float: right !important;
}
}

.navbar-left {
text-align: center;
}

.optionlist {
margin-bottom: 0;
padding-left: 0;
list-style: none;
margin: 7.5px -15px;
float: left!important;
}
.optionlist:before,
.optionlist:after {
content: " ";
display: table;
}
.optionlist:after {
clear: both;
}
.optionlist:before,
.optionlist:after {
content: " ";
display: table;
}
.optionlist:after {
clear: both;
}
.optionlist > li {
position: relative;
display: block;
}
.optionlist > li > a {
position: relative;
display: block;
padding: 10px 15px;
}
.optionlist > li > a:hover,
.optionlist > li > a:focus {
text-decoration: none;
background-color: #eeeeee;
}
.optionlist > li.disabled > a {
color: #999999;
}
.optionlist > li.disabled > a:hover,
.optionlist > li.disabled > a:focus {
color: #999999;
text-decoration: none;
background-color: transparent;
cursor: not-allowed;
}
.optionlist .open > a,
.optionlist .open > a:hover,
.optionlist .open > a:focus {
background-color: #eeeeee;
border-color: #428bca;
}
.optionlist .nav-divider {
height: 1px;
margin: 9px 0;
overflow: hidden;
background-color: #e5e5e5;
}
.optionlist > li > a > img {
max-width: none;
}
.optionlist > li > a {
padding-top: 10px;
padding-bottom: 10px;
line-height: 20px;
}
@media (max-width: 999px) {
.optionlist .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
box-shadow: none;
}
.optionlist .open .dropdown-menu > li > a,
.optionlist .open .dropdown-menu .dropdown-header {
padding: 5px 15px 5px 25px;
}
.optionlist .open .dropdown-menu > li > a {
line-height: 20px;
}
.optionlist .open .dropdown-menu > li > a:hover,
.optionlist .open .dropdown-menu > li > a:focus {
background-image: none;
}
}
@media (min-width: 1000px) {
.optionlist {
float: left;
margin: 0;
}
.optionlist > li {
float: left;
}
.optionlist > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
.optionlist.navbar-right:last-child {
margin-right: -15px;
}
}
.optionlist > li > a {
padding-bottom: 27px;
}
}

@media (min-width: 1000px) {
.navbar-toggle {
display: none;
}
}
.navbar-nav {
margin: 7.5px -15px;
}
.navbar-nav > li > a {
padding-top: 10px;
padding-bottom: 10px;
line-height: 20px;
}
@media (max-width: 999px) {
.navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
box-shadow: none;
}
.navbar-nav .open .dropdown-menu > li > a,
.navbar-nav .open .dropdown-menu .dropdown-header {
padding: 5px 15px 5px 25px;
}
.navbar-nav .open .dropdown-menu > li > a {
line-height: 20px;
}
.navbar-nav .open .dropdown-menu > li > a:hover,
.navbar-nav .open .dropdown-menu > li > a:focus {
background-image: none;
}
}
@media (min-width: 1000px) {
.navbar-nav {
float: left;
margin: 0;
}
.navbar-nav > li {
float: left;
}
.navbar-nav > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
.navbar-nav.navbar-right:last-child {
margin-right: -15px;
}
}

.nav {
margin-bottom: 0;
padding-left: 0;
list-style: none;
}
.nav:before,
.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav:before,
.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav > li {
position: relative;
display: block;
}
.nav > li > a {
position: relative;
display: block;
padding: 10px 15px;
}
.nav > li > a:hover,
.nav > li > a:focus {
text-decoration: none;
background-color: #eeeeee;
}
.nav > li.disabled > a {
color: #999999;
}
.nav > li.disabled > a:hover,
.nav > li.disabled > a:focus {
color: #999999;
text-decoration: none;
background-color: transparent;
cursor: not-allowed;
}
.nav .open > a,
.nav .open > a:hover,
.nav .open > a:focus {
background-color: #eeeeee;
border-color: #428bca;
}
.nav .nav-divider {
height: 1px;
margin: 9px 0;
overflow: hidden;
background-color: #e5e5e5;
}
.nav > li > a > img {
max-width: none;
}

.userbar{
//aggiungere stile navbar
.navbar;
.navbar-default; //taken both from Bootstrap
}

.navhead{
.navbar-header; //taken from Bootstrap
}

.brandname{
margin-top:10px;
margin-right:10px;
margin-left:5px;
}

.collapsebar{
.collapse;
.navbar-collapse;
}

.navbar-left{
text-align:center;
}

.optionlist{
.nav;
.navbar-nav;
float:left!important;
}

.gaslabel{
position: absolute;
width:100%;
color: @gas-color;
}

.navbar-right{
margin-top:5px;
}

最佳答案

您需要将 nave 链接移动到单个 ul 元素中,然后使用 css 进一步对齐和完成。

http://www.bootply.com/tsf41Uxykt#

                       <ul class="optionlist nav navbar-nav" ng-controller="menu_controller">
<li ng-controller="gas_controller" ng-repeat="gasname in gasnames" ng-class="{ 'active': $index == selectedIndex }" ng-click="itemClicked($index)">
<a href="#/{{peID}}/" ng-click="getID(gasname.id);">
gasname
</a>
<div class="gaslabel">110100</div>
</li>
<li markable="">
<a href="#/{{peID}}/">
<i class="fa fa-book"></i>Ordinare
</a>
</li>

<li markable="">
<a href="#/{{peID}}/paniere">
<i class="fa fa-shopping-cart"></i>Paniere
</a>
</li>
<li markable="">
<a href="#/{{peID}}/conto">
<i class="fa fa-user"></i>Conto
</a>
</li>
<li>
<div class="navbar-right">
<a class="navpic" href="#/{{peID}}/scheda"><img src="img/user_pic.png" alt="..." class="imgpic"></a>
<a class="titlenav" href="#/{{peID}}/scheda">Ciao {{name}}</a>
</div>
</li>
</ul>

关于css - Bootstrap 导航栏折叠对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24711906/

28 4 0