简体   繁体   English

Bootstrap 3导航栏固定顶部菜单项作为图像

[英]Bootstrap 3 navbar fixed top menu items as images

I'm creating template using Bootstrap v3.3.6. 我正在使用Bootstrap v3.3.6创建模板。 Here's the part of my template: 这是我模板的一部分:

在此处输入图片说明

As you can see I have navbar fixed at the top and I also have menu items that are icons or simply images embedded between <li></li> tags, user info icon and gear icon. 如您所见,我的导航栏固定在顶部,菜单项也是图标,或者仅仅是嵌入在<li></li>标签,用户信息图标和齿轮图标之间的图像。

What I don't know for sure is if I'm doing it correctly, I mean is there a special class in bootstrap that is specifically for menu items where you want to insert image. 我不确定的是我是否做得正确,我的意思是引导程序中有一个特殊的类,专门用于要在其中插入图像的菜单项。 Maybe those images are not supposed to be there. 也许这些图像不应该在那里。

Another question would be if I should place my logo image inside <a class="navbar-brand"></a> ? 另一个问题是我是否应该将徽标图像放在<a class="navbar-brand"></a> If I try to insert bigger logo image in height than navbar height then logo image isn't properly centered. 如果我尝试在高度上插入比导航栏高度更大的徽标图像,则徽标图像无法正确居中。 What is the easiest way to properly change navbar height and how to center images vertically in navbar? 正确更改导航栏高度的最简单方法是什么,以及如何在导航栏中垂直居中图像?

(Maybe that's too much code, but I wanna make sure that my question isn't lacking anything) only part where two images are inserted as navigation items are relevant (也许这是太多的代码,但是我想确保我的问题不缺少任何东西)只有一部分插入了两个图像作为导航项是相关的

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <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="#">Workout.lt</a>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav navbar-right">
        <li>
          <a href="#">Vardenis Pavardenis</a>
        </li>
        <li>
          <a href="#"><img src="images/user-info.png"></a>
        </li>
        <li>
          <a href="#"><img src="images/user-gear.png"></a>
        </li>
        <li>
          <a href="#">Services</a>
        </li>
        <li>
          <a href="#">Atsijungti</a>
        </li>
      </ul>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container -->
</nav>

To answer the second question, I put the image in the navbar-brand anchor and then use the inspector to adjust how the navbar looks. 为了回答第二个问题,我将图像放在导航栏品牌锚中,然后使用检查器调整导航栏的外观。 I copy that CSS into a separate document that overrides the default Bootstrap CSS. 我将该CSS复制到一个覆盖默认Bootstrap CSS的单独文档中。

<div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <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="../path/picture.jpg" alt="picture" height="90" width="180" /></a>
    </div>

Your CSS would look something like this: 您的CSS看起来像这样:

.nav-bar-brand { 
    height:90px; 
    width:100%;  /*or whatever width you wanted*/ 
} 

Again, using the inspector is always quicker than experimenting and then uploading the CSS document. 同样,使用检查器总是比尝试然后上传CSS文档更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM