html - Bootstrap 导航栏中的居中链接(在 li 内)

标签 html css twitter-bootstrap

我已经实现了解决方案 here几乎解决了我的问题,但是,我需要 <ul class="nav">以整个导航栏为中心,而不仅仅是与其相邻的元素(在我的例子中为 <a class="brand"><p class="navbar-text pull-right">)。

重要:我customized我的导航栏是96px而不是默认的 40px ,我想要 <ul class="nav">显示在其他元素的中心和“下方”,因为它将有自己的背景颜色等。

到目前为止,这是我的代码:

<div class="navbar navbar-inverse navbar-fixed-top center">
    <div class="navbar-inner">
        <div class="container-fluid">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a class="brand" href="/home"><img src="http://jayeshcp.files.wordpress.com/2013/03/twitter-bootstrap.jpg" style="width:400px;height:60px;" /></a>
            <div class="nav-collapse collapse">
                <ul class="nav">
                    <li><a href="#">One</a></li>
                    <li><a href="#">Two</a></li>
                    <li><a href="#">Three</a></li>
                    <li><a href="#">Four</a></li>
                </ul>
                <p class="navbar-text pull-right">
                    <input class="span2" type="text" placeholder="Email">
                    <input class="span2" type="password" placeholder="Password">
                </p>
            </div><!--/.nav-collapse -->
        </div>
    </div>
</div>

注意额外的 center我添加的类 - 来 self 链接到的解决方案。它看起来像这样:

.center.navbar .nav,
.center.navbar .nav > li {
    float:none;
    display:inline-block;
    *display:inline; /* ie7 fix */
    *zoom:1; /* hasLayout ie7 trigger */
    vertical-align: top;
}

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

.center .dropdown-menu {
    text-align: left;
}

如何将 ul 居中并在不破坏 Bootstrap 中的其他所有内容的情况下在上面填充它?如果有另一种货币,我们会提供更多的赏金!

编辑: jsfiddle 是 here (我粘贴了整个缩小的 css 文件(具有自定义的导航栏高度)而不是引用它,抱歉。在它下面是其他自定义项。)

最佳答案

p.navbar-text
{
    float: none;
    position: relative;
    text-align: right;
}
.navbar .nav
{
    display:block !important;
    float: right !important;
    width: 100%;
}

jsfiddle:http://jsfiddle.net/C7LWm/103/

这是将它放在下面而不是下面的解决方案:

.navbar .nav
{
   position: absolute;
   left:0;
   right:0;
   width: 100%;
   background-color:yellow;
}
p.navbar-text
{
   width: 440px;
   text-align:right;
   position:relative;
   z-index:2
}
.navbar .brand 
{ 
   position: relative; 
   z-index:2; 
   padding: 0; 
   width: 30%;
   height: 60px;
   background-image: url('http://placehold.it/400x60&text=Your Logo Here');
   background-repeat: no-repeat; background-size: contain;
   margin: 18px 0;
   background-position: center left
}
.navbar .brand img
{
   display:none;
}

Jsfiddle:http://jsfiddle.net/C7LWm/109/

关于html - Bootstrap 导航栏中的居中链接(在 li 内),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17453574/

相关文章:

javascript - 如何检查 div 的第一个 child 是否处于事件状态

html - CSS 元素 100% 的父元素

php - 仅在一页上动态调整 div 大小?

css - Bootstrap 结合媒体查询混合

html - 如何在没有间距的情况下进行多跨度推特 Bootstrap

javascript - 如何在容器特定的 scss 中包含 Bootstrap?

javascript - 我需要能够在 5 列中显示 2 行文本,并且每列文本需要不同,全部基于 1 个下拉列表?

HTML 术语

html - 元素不以 :after 为中心

css - 标题图像底部边框