Navbar中的中心品牌徽标

Navbar中的中心品牌徽标

本文介绍了Bootstrap Navbar中的中心品牌徽标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现Bootstrap 3导航栏,以使品牌徽标始终保留在中间.这是代码:

I am trying to implement a Bootstrap 3 navbar so that the brand logo to always remain in the middle. This is the code:

<div class="navbar navbar-fixed-top navbar-default">
  <div class="navbar-inner">
    <div class="container">
      <button type="button" style="float: left;" class="pull-left btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      </button>
      <a class="brand" style="margin: 0; float: none;" href="#">
      <img src="/Content/themes/next/images/logo.png" /></a>
      <div class="nav-collapse">
        <ul class="nav">
          <li> <a href="#">Item 1</a></li>
          <li> <a href="#">Item 1</a></li>
          <li> <a href="#">Item 1</a></li>
        </ul>
      </div>
      <ul class="nav pull-right">
        <li>
          <a href="#">
            <div class="nextCog"></div>
          </a>
        </li>
      </ul>
      <span class="navbar-text pull-right">superpup1 </span>
    </div>
  </div>
</div>

它使导航栏看起来很漂亮:

It makes a nice looking navbar:

但是,我希望徽标(绿色)始终保持在中间.我将这种样式添加到带有"brand"类的标签中:

However, I would like the logo (green) remain in the middle persistently. I am adding this style to the tag with "brand" class:

<a class="brand" style="margin: 0; float: none; text-align:center" href="#">
  <img src="/Content/themes/next/images/logo.png" />
</a>

部分解决了这个问题:徽标位于中间,但将其余的导航栏元素向下推:

It partially solves the problem: the logo is in the middle but it pushes the rest of the navbar elements down:

这是我要消除的不良影响.您能提出解决方案吗?从一开始就将徽标居中可能是错误的方法吗?

This is an undesirable effect that I would like to eliminate. Could you suggest a solution? Maybe it's a wrong approach to centering a logo from the start ?

推荐答案

尝试一下:

.navbar {
    position: relative;
}
.brand {
    position: absolute;
    left: 50%;
    margin-left: -50px !important;  /* 50% of your logo width */
    display: block;
}

将徽标居中放置徽标宽度的50%,减去徽标宽度的一半,这样在放大和缩小时就不会出现问题.

Centering your logo by 50% and minus half of your logo width so that it won't have problem when zooming in and out.

请参见小提琴

这篇关于Bootstrap Navbar中的中心品牌徽标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 15:54