1

我从以下代码开始,它应该使用 Jekyll(和引导程序)生成我网站的导航栏:

  <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>

但是,我想在{{ site .title }}. 为此,我尝试使用以下代码:

 <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>

问题是:

  1. 徽标位于文本的右侧
  2. 现在文本+徽标和页面名称之间有一个巨大的水平空间。

不良输出样本

我想这很简单,但我不知道如何解决它。如何将徽标放置在文本的左侧并避免不良的 h 间距。一个好处是确保文本行相对于徽标是 v 居中的。

4

1 回答 1

1

尝试为 img 宽度和高度提供固定值

它提供了图像实际宽度的精确空间!

.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>

我已经更新了片段

于 2015-05-30T12:54:45.800 回答