1

I started with the following code, that should generate the navigation bar of my site using Jekyll (and bootstrap):

  <nav class="navbar navbar-default" role="navigation">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#jb-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="{{ HOME_PATH }}">{{ site.title }}</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="jb-navbar-collapse">
      <ul class="nav navbar-nav">
        {% assign pages_list = site.pages %}
        {% assign group = 'navigation' %}
        {% include JB/pages_list %}
      </ul>
    </div><!-- /.navbar-collapse -->
  </nav>

However, I want to have a logo in front of {{ site .title }}. To that end, I tried to use the following code:

 <nav class="navbar navbar-default" role="navigation">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#jb-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 style="text-align:left">
        <a href="{{ HOME_PATH }}"><img src="{{ site.logoimg }}" height="5%" width="5%"/></a>
        <a class="navbar-brand" href="{{ HOME_PATH }}">{{ site.title }}</a>
      </div>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="jb-navbar-collapse">
      <ul class="nav navbar-nav">
        {% assign pages_list = site.pages %}
        {% assign group = 'navigation' %}
        {% include JB/pages_list %}
      </ul>
    </div><!-- /.navbar-collapse -->
  </nav>

The problems are:

  1. The logo is to the right of the text
  2. Now there's a huge horizontal space between the text+logo and the pages' names.

Sample of the bad output

I guess it is something simple, but I don't know how to tackle it. How can I place the logo to the left of the text and avoid the bad h-spacing. A bonus would be to make sure that the line of text is v-centered with respect to the logo.

Dror
  • 9,918
  • 17
  • 70
  • 137

1 Answers1

1

Try To Give Fixed values to img widht & height

it is giving exact space of your image's actual width!

.navbar-brand-fix,
.navbar-nav-fix li a
{
  line-height:50px !important;
  vertical-align:middle !important;
  padding-top:25px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />

<nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#jb-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>
        <a class="pull-left" href="#"><img src="http://placehold.it/600x200" height="100px" width="100px"/></a>
        <a class="navbar-brand navbar-brand-fix" href="#">TITle</a>
      </div>
    </div>
    <div class="collapse navbar-collapse" id="jb-navbar-collapse">
      <ul class="nav navbar-nav navbar-nav-fix">
        <li><a href="#">Names</a></li>
        <li><a href="#">Names</a></li>
        <li><a href="#">Names</a></li>
        <li><a href="#">Names</a></li>
      </ul>
    </div>
  </nav>

I have updated snippet

Sumeet Gohil
  • 171
  • 1
  • 10
  • If I try to enlarge the logo, then I notice that the text to its right is not vertically aligned. Is there a way to solve it? – Dror May 30 '15 at 20:12
  • can you edit above snippet so i can see , what exact issue you are facing. i'll suggest used fixed values! – Sumeet Gohil Jun 01 '15 at 05:42
  • I simply tried to use higher (fixed) values, and then it was visible that the text line is not aligned with the vertical center of the logo – Dror Jun 01 '15 at 12:34
  • I have just now updated snippet , you want something like this ? – Sumeet Gohil Jun 02 '15 at 09:56
  • Where should I add the `css` part that you added at the beginning? In which file should it be included? – Dror Jun 03 '15 at 20:31
  • to the default `css` file , what is your Project's Folder & File Structure? – Sumeet Gohil Jun 04 '15 at 07:13
  • I can see 3 Themes which ever theme you have selected just `append` above lines to `style.css` file For Instance , Theme => Bootstarp-3 , This File => drorata.github.io/assets/themes/bootstrap-3/css/style.css – Sumeet Gohil Jun 04 '15 at 09:45