html – 如何在bootstrap导航栏中添加自己的图标

前端之家收集整理的这篇文章主要介绍了html – 如何在bootstrap导航栏中添加自己的图标前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在一个项目上工作,我开始在导航栏上.我想知道是否有可能在每个菜单栏旁边添加我自己的图标?例如,这个图标: https://www.dropbox.com/sh/0be3c7ub4245kd6/zNMrvFi6Wq

像这样:

> DEMO

码:

<!-- Fixed navbar -->
    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".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="#">Project name</a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>

          </ul>

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

    <div class="container">

      <!-- Main component for a primary marketing message or call to action -->
      <div class="jumbotron">
        <h1>Navbar example</h1>
        <p>This example is a quick exercise to illustrate how the default,static and fixed to top navbar work. It includes the responsive CSS and HTML,so it also adapts to your viewport and device.</p>
        <p>To see the difference between static and fixed top navbars,just scroll.</p>
        <p>
          <a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs &raquo;</a>
        </p>
      </div>

    </div> <!-- /container -->

解决方法

这是一种在不添加任何额外标记的情况下执行此操作的方法,但您确实需要为每个锚链接添加唯一的类.

CSS:

.navbar-default .navbar-nav>.active>a:before,.navbar-nav>li>a:before {
    background-repeat: no-repeat;
    background-position: 0 top;
    content: "";
    display: inline-block;
    height: 29px;
    margin-right: 10px;
    vertical-align: middle;
    width: 29px;
}

.navbar-default .navbar-nav>.active>a.home:before,.navbar-nav>li>a.home:before { background-image: url('https://dl.dropBoxusercontent.com/sh/0be3c7ub4245kd6/18Xnfucw14/home.png'); }

.navbar-default .navbar-nav>.active>a.about:before,.navbar-nav>li>a.about:before {  background-image: url('https://dl.dropBoxusercontent.com/sh/0be3c7ub4245kd6/DhXiON5YiL/kveld.png'); }

.navbar-default .navbar-nav>.active>a.contact:before,.navbar-nav>li>a.contact:before {  background-image: url('https://dl.dropBoxusercontent.com/sh/0be3c7ub4245kd6/_fidqgglaS/sol.png'); }

您可以在此处查看结果:http://jsfiddle.net/2WvpV/

你需要玩边距和填充.此外,这并不完美,因为您应该使用相对大小而不是像素.

猜你在找的HTML相关文章