Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering an Image in a twitter bootstrap navbar

Here is my live site: http://ancient-badlands-4040.herokuapp.com/

I am trying to center my image and also have the links align vertically with the image.

I got a lot of help with this so far after reading this post Twitter Bootstrap - centering brand logo in navbar

I was successful earlier centering my image by adjusting my "brand" class (I set the width to 28%). Unfortunately, I had to adjust the "navbar" class's width as well, after adjusting the width it changed the position of my logo.

I changed my code to the following below, I am trying to center my image and have the links line up evenly with my center image.

Any help would be appreciated, thanks! :)

HTML: **Updated divs and ul classes

    <div class="navbar navbar-fixed-top">
  <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>
      <div class="nav-collapse collapse">
        <ul class="nav pull-right">
          <li><a>CODEY</a>
          </li>
          <li> <a>CODEY</a></li>
        </ul>

        <ul class="nav pull-left">
          <li><a>CODEY</a></li>
          <li><a>CODEY</a></li>
          <li><a>CODEY</a></li>
          </ul>

          <a class="brand"></a>
          <%= image_tag 'ctclogonewnobg.png', alt: 'logo' %>

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

CSS:

$navbarLinkColor: #90fce8;
$navbarBackground: #ff3600;
$navbarBackgroundHighlight: #ff3600;
$navbarText: Archivo Black, sans-serif;
@import url(http://fonts.googleapis.com/css?family=Archivo+Black);


@import 'bootstrap';

body {

    background: url('[email protected]');
}


@import 'bootstrap-responsive';

.navbar-inner {
    @include box-shadow(none !important);
    border: 0;
    width: 100%%;
    margin: auto;
}



.navbar .brand {
    margin-left: auto;
    margin-right: auto;
    width: 20px;
    float: none;

}
like image 600
HelloWorld Avatar asked Oct 03 '22 16:10

HelloWorld


1 Answers

Here are a couple examples for you in a CodePen - http://codepen.io/michaellee/pen/nLmJa

Basically the first example uses display: inline-block; to align everything in a line and vertical-align: middle; the blocks.

The second example is more like yours where you can float the nav's to the left and right and use padding to create a vertically, centered look and feel.

HTML

<header>
  <ul class="nav-left">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
  </ul>
  <span class="logo">Logo!</span>
  <ul class="nav-right">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
  </ul>
</header>
<br />
<header class="second">
  <ul class="nav-left">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
  </ul>
  <span class="logo">Logo!</span>
  <ul class="nav-right">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
  </ul>
</header>

CSS

header{
  width: 100%;
  text-align: center;
  background: #e63100;
  display:block;
  overflow: hidden;
}
ul{
  list-style: none;
  display: inline-block;
  vertical-align: middle;
  margin: 0;
  padding: 0;
  li{
    display: inline-block;
  }
}

.logo{
  font-size: 30px;
  vertical-align: middle;
  margin: 0 40px;
}

.second{
  .nav-left{
    float: left;
  }
  ul{
    padding: 30px 0;
  }
  .nav-right{
    float: right;
  }
  .logo{
    padding: 20px 0;
    display: inline-block;
  }
}
like image 62
michaellee Avatar answered Oct 07 '22 20:10

michaellee