如何使一个右对齐的nav元素不会在移动设备上崩溃?

时间:2016-04-12 05:07:45

标签: html css twitter-bootstrap

我有一个带有一堆导航的导航栏。我希望只有通知下拉列表才能在xs设备上折叠。我还需要通知位于特定位置(搜索表单右侧)。

这是原始导航:

  <nav class="navbar navbar-inverse" role="navigation">
  <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="#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="/"><span class="logo">logo</span></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="navbar-collapse-1">
      <ul class="nav navbar-nav"> 
        <li><a href="/">Home</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Actions <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action 1</a></li>
            <li><a href="#">Action 2</a></li>
          </ul>
        </li>

        <li><a href="#">Posts</a></li>  

        <form class="navbar-form navbar-left search-form" role="search" action="/home/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
          <div class="form-group">
            <input type="text" name="q" id="q" class="form-control" placeholder="Search">
            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
          </div>
        </form>      
      </ul>

      <ul class="nav navbar-nav navbar-right">    
          <li class="dropdown">
            <a href="#" id="notification-circle" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                <i title="Notifications" class="fa fa-circle fa-lg"></i>

            </a>
            <ul class="dropdown-menu" id="notifications-ul">
              <li><a href="#">All Notifications...</a></li>
            </ul>  
          </li>

          <li><a href="#">Help</a></li>
          <li><a href="#">Logout</a></li>

      </ul>

    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

目前此导航在xs设备上折叠,这是一个问题,因为当有新通知时,通知按钮会亮起一个数字,如果通知折叠,该信息将不会显示给用户。

尝试1: 我尝试将通知移动到navbar-header,但这会将通知呈现在搜索的左侧,这是不可接受的。

尝试2: 我还尝试创建两个通知 - 一个在标题中的xs中可见,一个隐藏在xs中,但它会导致所有类型的怪异 - 例如,下拉列表项在移动视图中显示为单独的圆圈。以下是我尝试的一种变体:

  <nav class="navbar navbar-inverse" role="navigation">
  <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="#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="/"><span class="logo">logo</span></a>
      <ul class="navbar-brand visible-xs-inline">    
        <li class="dropdown">
          <a href="#" id="notification-circle" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
              <i title="Notifications" class="fa fa-circle fa-lg"></i>
          </a>
          <ul class="dropdown-menu" id="notifications-ul">
            <li><a href="#">All Notifications...</a></li>
          </ul>  
        </li>
      </ul>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="navbar-collapse-1">
      <ul class="nav navbar-nav"> 
        <li><a href="/">Home</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Actions <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action 1</a></li>
            <li><a href="#">Action 2</a></li>
          </ul>
        </li>

        <li><a href="#">Posts</a></li>  

        <form class="navbar-form navbar-left search-form" role="search" action="/home/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
          <div class="form-group">
            <input type="text" name="q" id="q" class="form-control" placeholder="Search">
            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
          </div>
        </form>      
      </ul>


      <ul class="nav navbar-nav navbar-right">  
        <li><a href="#">Help</a></li>
        <li><a href="#">Logout</a></li>
      </ul>

      <ul class="nav navbar-nav navbar-right hidden-xs">    
        <li class="dropdown">
          <a href="#" id="notification-circle" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
              <i title="Notifications" class="fa fa-circle fa-lg"></i>
          </a>
          <ul class="dropdown-menu" id="notifications-ul">
            <li><a href="#">All Notifications...</a></li>
          </ul>  
        </li>
      </ul>

    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

以下是bootply链接:http://www.bootply.com/SZbrMZoiXq

如何让移动设备中的通知下拉列表不会崩溃?

例如,引导程序中是否有一个类跳过像'no-collapse'那样的崩溃,我可以应用于我想要跳过折叠的导航?

0 个答案:

没有答案