使用Bootstrap导航菜单对齐

时间:2016-02-23 04:02:19

标签: css twitter-bootstrap

我有这个菜单:

enter image description here

使用此引导代码:

<section class="mbr-navbar mbr-navbar--freeze mbr-navbar--absolute mbr-navbar--transparent mbr-navbar--sticky mbr-navbar--auto-collapse" id="menu-0">
<div class="mbr-navbar__section mbr-section">
    <div class="mbr-section__container container">
        <div class="mbr-navbar__container">
            <div class="mbr-navbar__column mbr-navbar__column--s mbr-navbar__brand">
                <span class="mbr-navbar__brand-link mbr-brand mbr-brand--inline">

                </span>
            </div>
            <div class="mbr-navbar__hamburger mbr-hamburger text-white"><span class="mbr-hamburger__line"></span></div>
            <div class="mbr-navbar__column mbr-navbar__menu">
                <nav class="mbr-navbar__menu-box mbr-navbar__menu-box--inline-right">
                    <div class="mbr-navbar__column">
                        <ul class="mbr-navbar__items mbr-navbar__items--left mbr-buttons mbr-buttons--freeze mbr-buttons--left btn-decorator mbr-buttons--active mbr-buttons--only-links">
                            <li class="mbr-navbar__item" style="float: left"><a class="mbr-buttons__link btn text-white" href="#">SIGN IN</a></li>
                        </ul>
                        <ul class="mbr-navbar__items mbr-navbar__items--right mbr-buttons mbr-buttons--freeze mbr-buttons--right btn-decorator mbr-buttons--active mbr-buttons--only-links"><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="#">HOME</a></li><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="#">ABOUT</a></li><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="#">CONTACT</a></li></ul></div>

                </nav>
            </div>
        </div>
    </div>
</div></section>

如何移动菜单“登录”以使菜单如下:

enter image description here

3 个答案:

答案 0 :(得分:0)

需要更多代码才能获得更好的答案,但添加&#34; float:left&#34;登录按钮的属性应该这样做,但建议未来:

尝试将代码基于Bootstrap在其文档中提供的模板:http://jsfiddle.net/ycUB6/10708/

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <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="#">Brand</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">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

答案 1 :(得分:0)

您正在使用的代码是mobilirise。因此,您不必重新编写上面的整个节目,只需复制完整的注册行,然后从&#39; ul&#39;标签

`<ul class="mbr-navbar__items mbr-navbar__items--left mbr-buttons mbr-buttons--freeze mbr-buttons--left btn-decorator mbr-buttons--active mbr-buttons--only-links">
    <li class="mbr-navbar__item" style="float: left">
        <a class="mbr-buttons__link btn text-white" href="#">SIGN IN</a></li>
</ul>`

并将其放在品牌名称旁边,如show

 <div class="mbr-navbar__column mbr-navbar__column--s mbr-navbar__brand">
                <span class="mbr-navbar__brand-link mbr-brand mbr-brand--inline">

                </span>
                <ul class="mbr-navbar__items mbr-navbar__items--left mbr-buttons mbr-buttons--freeze mbr-buttons--left btn-decorator mbr-buttons--active mbr-buttons--only-links">
                    <li class="mbr-navbar__item" style="float: left"><a class="mbr-buttons__link btn text-white" href="#">SIGN IN</a></li>
                </ul>
            </div

这样整个代码就像这样

 `<section class="mbr-navbar mbr-navbar--freeze mbr-navbar--absolute mbr-navbar--transparent mbr-navbar--sticky mbr-navbar--auto-collapse" id="menu-0">
<div class="mbr-navbar__section mbr-section">
    <div class="mbr-section__container container">
        <div class="mbr-navbar__container">
            <div class="mbr-navbar__column mbr-navbar__column--s mbr-navbar__brand">
                <span class="mbr-navbar__brand-link mbr-brand mbr-brand--inline">
                </span>
                <ul class="mbr-navbar__items mbr-navbar__items--left mbr-buttons mbr-buttons--freeze mbr-buttons--left btn-decorator mbr-buttons--active mbr-buttons--only-links">
                    <li class="mbr-navbar__item" style="float: left"><a class="mbr-buttons__link btn text-white" href="#">SIGN IN</a></li>
                </ul>
            </div>
            <div class="mbr-navbar__hamburger mbr-hamburger text-white"><span class="mbr-hamburger__line"></span></div>
            <div class="mbr-navbar__column mbr-navbar__menu">
                <nav class="mbr-navbar__menu-box mbr-navbar__menu-box--inline-right">
                    <div class="mbr-navbar__column">
                        <ul class="mbr-navbar__items mbr-navbar__items--right mbr-buttons mbr-buttons--freeze mbr-buttons--right btn-decorator mbr-buttons--active mbr-buttons--only-links"><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="#">HOME</a></li><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="#">ABOUT</a></li><li class="mbr-navbar__item"><a class="mbr-buttons__link btn text-white" href="#">CONTACT</a></li></ul></div>
                </nav>
            </div>
        </div>
    </div>
</div></section>`

抱歉,我的回复似乎很长

答案 2 :(得分:0)

float: left用于其父元素ul。代码下面是

<ul  style="float: left" class="mbr-navbar__items mbr-navbar__items--left mbr-buttons mbr-buttons--freeze mbr-buttons--left btn-decorator mbr-buttons--active mbr-buttons--only-links">
  <li class="mbr-navbar__item">
     <a class="mbr-buttons__link btn text-white" href="#">SIGN IN</a>
  </li>
</ul>