尝试在同一行显示链接文本和链接图标

时间:2014-08-18 15:03:37

标签: javascript jquery html css twitter-bootstrap

我正在使用bootstrap来创建响应式导航,而我正在使用bootstrap提供的一个图标来创建一个显示/隐藏菜单。问题是它在不同的行上显示箭头。有没有办法在一行上显示文本旁边的箭头?

以下是演示:http://jsfiddle.net/0L6g87h2/

这是伴随着这个小提琴的代码,使这个自包含:

<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3 col-lg-2">
  <div class="sidebar-nav">
    <div class="navbar navbar-default" role="navigation">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-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>
      <span class="visible-xs navbar-brand">Left Navigation</span>
      </div><!--/.navbar-header -->
      <div class="navbar-collapse collapse sidebar-navbar-collapse">
      <nav id="leftNav" role="navigation" aria-label="Left Navigation">
      <!-- TemplateBeginEditable name="Left Navigation" -->  
        <ul class="nav navbar-nav"> 
          <li><a href="#.html">Home</a></li>
          <li><a href="#"><strong>Cars</strong></a>
            <a href="#ELP" class="expander" ><span class="glyphicon glyphicon-circle-arrow-right"></span></a>
            <ul id="ELP">
              <li><a href="#">BMW</a></li>
              <li><a href="#">Honda</a></li>
              <li><a href="#">Toyota</a></li>   
            </ul>
          </li> 
        </ul> 
      </nav> <!-- /Left Navigation -->
      </div> 
      <!--/.nav-collapse -->
    </div> <!--/.navbar-default -->
    </div> <!--/.sidebar-nav -->
  </div> <!--/.col-sm-3 col-md-3 col-lg-2-->  

3 个答案:

答案 0 :(得分:3)

您可以在span元素中添加图标aUpdated fiddle

<a href="">
    <strong>Cars</strong> 
    <span class="glyphicon glyphicon-circle-arrow-right"></span
</a>

<小时/> 您还可以使用bootstrap的pull-leftpull-right类。 Updated fiddle

<a href="" class="pull-left">
    <strong>Cars</strong>
</a>

<a href="" class="pull-right">
    <span class="glyphicon glyphicon-circle-arrow-right"></span>
</a>

答案 1 :(得分:2)

您可以将两个元素包装在一个范围内,并将范围设置为display:inline或inline-block。

<span style="display:inline-block;">
    <a href="../Gateway/index.html"><strong>Cars</strong></a>
    <a href="#ELP" class="expander" >
        <span class="glyphicon glyphicon-circle-arrow-right"></span>
    </a>
</span>

http://jsfiddle.net/0L6g87h2/2/

答案 2 :(得分:1)

试试这个......

<a href="#">
  <span class="glyphicon glyphicon-chevron-right"></span> Demo
</a>