中心bootstrap navbar品牌标志

时间:2018-02-19 23:22:18

标签: html css twitter-bootstrap

我试图将我的Bootstrap导航栏品牌徽标死点放在中心位置,但似乎有点向右推......我该如何解决这个问题?

在这里小提琴:https://jsfiddle.net/62tfdt3o/3/

HTML

<div class="header" id="navbar-header">
  <div navbar-shrink offset="50" scroll-class="navbar-shrink" class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">

        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#js-navbar-collapse">
              <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="/">
              <img src="http://marquesslondon.herokuapp.com/images/logo.daa5186d.png">
            </a>
      </div>

      <div style="display: block">
        <div class="collapse navbar-collapse" id="js-navbar-collapse">
          <ul class="nav navbar-nav" id="navbar">
            <li><a href="/">HOME</a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" data-toggle="dropdown" href="#">TAILORING</a>
              <ul class="dropdown-menu">
                <li><a href="/process">Process</a></li>
                <li><a href="/look">Our Look</a></li>
              </ul>
            </li>
            <li><a ng-href="/lifestyle">LIFESTYLE</a></li>
            <li><a ng-href="/story">STORY</a></li>
            <li><a ng-href="/contact">GET IN TOUCH</a></li>
          </ul>
        </div>
      </div>

    </div>
  </div>
</div>

CSS

/*=======================================================
Header, footer and navbar
========================================================*/

.navbar .navbar-nav {
  display: inline-block;
  float: none;
  margin-top: 6.5em;
  font-family: 'Ubuntu', sans-serif;
  font-weight: 400;
  font-style: normal;
  letter-spacing: 5px;
  text-transform: uppercase;
  font-size: 14px;
}

.navbar {
  position: relative;
}

.navbar-brand {
  position: absolute;
  left: 50%;
  display: block;
}

.navbar-shrink .navbar-nav {
  display: none;
}

.navbar-shrink.navbar {
  height: 6em;
}

.navbar-shrink.navbar>.container>.navbar-header>.navbar-brand img {
  width: 250px;
  height: 44px;
}

.navbar-default .navbar-nav>li>a {
  color: #fff;
  font-weight: 300;
}

.navbar-default .navbar-nav>li>a:focus,
.navbar-default .navbar-nav>li>.active {
  color: #808ba0;
}

.navbar-default .navbar-nav>li>a:hover {
  color: #808ba0;
  font-weight: 300;
}

#navbar-header {
  transition: 2s ease-in-out;
}

.navbar-default {
  background-color: rgba(51, 55, 65, 0.9);
}

.navbar-default.navbar-shrink {
  background-color: rgba(51, 55, 65, 0.9);
}

.navbar {
  position: relative;
  border-radius: 0px;
  border: 0px;
  height: 10.5em;
  -webkit-transition: height 300ms ease-in-out;
  -moz-transition: height 300ms ease-in-out;
  -o-transition: height 300ms ease-in-out;
  transition: height 300ms ease-in-out;
}

.navbar-fixed-top {
  position: fixed !important;
}

.navbar-brand {
  position: absolute;
  display: block;
}

.navbar-brand img {
  width: 250px;
  height: 44px;
}

.nav {
  text-align: center;
}

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

.dropdown:hover .dropdown-menu {
  display: block;
  margin-top: 0;
}

.mq-footer {
  text-align: center;
  font-family: 'Ubuntu', sans-serif;
  padding-bottom: 2em;
}

.mq-footer>.container>#footer-copyright {
  font-size: 12px;
  color: #737373;
}

.footer-icon {
  font-size: 25px;
  color: #737373;
  opacity: 0.5;
  padding-top: 1em;
  padding-right: 0.25em;
}

.footer-icon:hover {
  opacity: 1;
  cursor: pointer;
}

#footer-copyright {
  margin-top: 2em;
}

#footer-links {
  margin-top: 2em;
}

#footer-links ul {
  padding-left: 25px;
}

#footer-links ul li {
  display: inline;
  margin-right: 25px;
}

#footer-links ul li a {
  color: #333741;
}

2 个答案:

答案 0 :(得分:2)

你可以试试这个。

我做的是创建了一个div(.navbar-logo),它将.navbar-brand括起来,然后应用Flexbox将徽标居中。

然后我将一些CSS实现到.navbar-toggle以使其定位。

然后将宽度设置为.navbar-header以在桌面视图中进行对齐。

/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
body,
html {
  height: 100%;
  margin: 0;
}

/*=======================================================
Header, footer and navbar
========================================================*/

.navbar-logo{
  display:flex;
  justify-content:center;
  align-items:center;
  height:50px;
  width:100%;
}

.navbar-toggle{
  position:absolute;
  top:5px;
  right:5px;
}

.navbar-header{
  width:100%;
}

.navbar .navbar-nav {
  display: inline-block;
  float: none;
  margin-top: 2em;
  font-family: 'Ubuntu', sans-serif;
  font-weight: 400;
  font-style: normal;
  letter-spacing: 5px;
  text-transform: uppercase;
  font-size: 14px;
}

.navbar {
  position: relative;
}


.navbar-shrink .navbar-nav {
  display: none;
}

.navbar-shrink.navbar {
  height: 6em;
}

.navbar-shrink.navbar>.container>.navbar-header>.navbar-brand img {
  width: 250px;
  height: 44px;
}

.navbar-default .navbar-nav>li>a {
  color: #fff;
  font-weight: 300;
}

.navbar-default .navbar-nav>li>a:focus,
.navbar-default .navbar-nav>li>.active {
  color: #808ba0;
}

.navbar-default .navbar-nav>li>a:hover {
  color: #808ba0;
  font-weight: 300;
}

#navbar-header {
  transition: 2s ease-in-out;
}

.navbar-default {
  background-color: rgba(51, 55, 65, 0.9);
}

.navbar-default.navbar-shrink {
  background-color: rgba(51, 55, 65, 0.9);
}

.navbar {
  position: relative;
  border-radius: 0px;
  border: 0px;
  height: 10.5em;
  -webkit-transition: height 300ms ease-in-out;
  -moz-transition: height 300ms ease-in-out;
  -o-transition: height 300ms ease-in-out;
  transition: height 300ms ease-in-out;
}

.navbar-fixed-top {
  position: fixed !important;
}

.navbar-brand img {
  width: 250px;
  height: 44px;
}

.nav {
  text-align: center;
}

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

.dropdown:hover .dropdown-menu {
  display: block;
  margin-top: 0;
}

.mq-footer {
  text-align: center;
  font-family: 'Ubuntu', sans-serif;
  padding-bottom: 2em;
}

.mq-footer>.container>#footer-copyright {
  font-size: 12px;
  color: #737373;
}

.footer-icon {
  font-size: 25px;
  color: #737373;
  opacity: 0.5;
  padding-top: 1em;
  padding-right: 0.25em;
}

.footer-icon:hover {
  opacity: 1;
  cursor: pointer;
}

#footer-copyright {
  margin-top: 2em;
}

#footer-links {
  margin-top: 2em;
}

#footer-links ul {
  padding-left: 25px;
}

#footer-links ul li {
  display: inline;
  margin-right: 25px;
}

#footer-links ul li a {
  color: #333741;
}
<div class="header" id="navbar-header">
  <div navbar-shrink offset="50" scroll-class="navbar-shrink" class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <div class="navbar-logo">
        <a class="navbar-brand" href="/">
              <img src="http://marquesslondon.herokuapp.com/images/logo.daa5186d.png">
        </a>
        </div>
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#js-navbar-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
      </div>
      <div style="display: block">
        <div class="collapse navbar-collapse" id="js-navbar-collapse">
          <ul class="nav navbar-nav" id="navbar">
            <li><a href="/">HOME</a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" data-toggle="dropdown" href="#">TAILORING</a>
              <ul class="dropdown-menu">
                <li><a href="/process">Process</a></li>
                <li><a href="/look">Our Look</a></li>
              </ul>
            </li>
            <li><a ng-href="/lifestyle">LIFESTYLE</a></li>
            <li><a ng-href="/story">STORY</a></li>
            <li><a ng-href="/contact">GET IN TOUCH</a></li>
          </ul>
        </div>
      </div>

    </div>
  </div>
</div>

希望这有帮助。

答案 1 :(得分:0)

.navbar-brand{
    display: flex;
    justify-content: center;
    width: 100%;
    left: 0;
}

希望此代码能解决您的问题