使用引导程序 3
我在我的 global.less 文件中添加了三个类来扩充引导程序 navbar.less 类。
这种方法适用于所有响应式@media 规则大小,但您需要根据菜单项的宽度调整字体大小和菜单折叠点(这种方法绝对定位导航栏品牌 - 它“浮动”在其他菜单项)。
风格:
.navbar-brand-centered {
position: absolute;
top: 0;
left: 50%;
height: 50px;
width: 200px; /* bootstrap has max-width: 200px rule */
margin-left: -100px;
margin-top: 8px;
text-align: center;
}
.navbar-brand-centered {
color: @navbar-inverse-brand-color;
&:hover,
&:focus {
color: @navbar-inverse-brand-hover-color;
background-color: @navbar-inverse-brand-hover-bg;
}
}
.navbar-brand-centered {
display: block;
max-width: 200px;
margin-left: auto;
margin-right: auto;
padding: @navbar-padding-vertical @navbar-padding-horizontal;
font-size: @font-size-large;
font-weight: 500;
line-height: @line-height-computed;
color: @navbar-brand-color;
text-align: center;
&:hover,
&:focus {
color: @navbar-brand-hover-color;
text-decoration: none;
background-color: @navbar-brand-hover-bg;
}
}
用法:
<div class="navbar navbar-fixed-top">
<!-- .navbar-toggle is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Be sure to leave the brand out here if you want it shown -->
<a class="navbar-brand-centered" href="/"><span style="font-size: 2em">mess<span style="color: red;">2</span>dress</span></a>
<!-- Place everything within .navbar-collapse to hide it until above 768px -->
<div class="nav-collapse collapse navbar-responsive-collapse">
<!-- YOUR MENU ITEMS HERE -->
这对我有用,但我确信有更好的方法可以与 bootstrap 实现的基于浮点的方法集成。接受反馈。