如何让这个Bootstrap导航栏在移动设备上看起来整洁?

时间:2014-09-26 03:46:02

标签: css html5 twitter-bootstrap responsive-design twitter-bootstrap-3

你可以看到它live here

以下是手机屏幕截图:

Messed-up Mobile Navbar Bootstrap

这是已消毒的HTML:

    <header class="header">
      <hgroup class="pull-left">
        <h1 class="site-title">
          <a rel="home" title="Von" href="index.html">
            <i class="fa fa-lemon-o"></i> Von
          </a>
        </h1>
      </hgroup>
      <div id="togglesidebar" class="btn btn-primary pull-right">
        <i class="fa fa-bars"></i>
      </div>

                <!-- Single button -->
                <div class="btn-group">
                  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                    Action <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="#">Action</a></li>
                    <li><a href="#">Another action</a></li>
                    <li><a href="#">Something else here</a></li>
                    <li class="divider"></li>
                    <li><a href="#">Separated link</a></li>
                  </ul>
                </div>

            <!-- Search Bar -->
            <div class="container">
                <div class="row">
                    <div class="col-xs-6 col-xs-offset-2">
                        <div class="input-group">
                            <div class="input-group-btn search-panel">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span id="search_concept">Filter by</span> <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                  <li><a href="#contains">Contains</a></li>
                                  <li><a href="#its_equal">It's equal</a></li>
                                  <li><a href="#greather_than">Greather than ></a></li>
                                  <li><a href="#less_than">Less than < </a></li>
                                  <li class="divider"></li>
                                  <li><a href="#all">Anything</a></li>
                                </ul>
                            </div>
                            <input type="hidden" name="search_param" value="all" id="search_param">
                            <input type="text" class="form-control" name="x" placeholder="Search term...">
                            <span class="input-group-btn">
                                <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span></button>
                            </span>
                        </div>
                    </div>
                </div>
            </div> <!-- /search-bar -->
  </header> <!-- /header -->

在实时版本中,徽标为153px X 50px

更新1:

根据Darshak的建议,这就是移动版的样子。更好,但仍需要调整。

Mobile-Menu-Responsive

2 个答案:

答案 0 :(得分:1)

试试这个。我尝试对您的设计进行响应式查看,并在您的结构中修改一些类。 我把这个结构放在你给定的链接上。

<header class="header clearfix">
  <div class="row masthead clearfix">
    <hgroup class="col-xs-6 col-sm-6 col-md-3 col-lg-3">
      <div class="site-title">
        <a href="/">
          <img alt="Ognrlogo" height="50" src="/assets/ognrlogo-232e94e86f40eeb3021490f5cf1e1a48.png" width="153" class="img-responsive" style="
    margin: 0;
">
        </a>
        <br>
        <span class="">On The Ground News Report</span>
      </div>
    </hgroup>

    <div class="col-xs-6 col-sm-6 col-md-2 col-lg-2 masthead-group-2 text-right">
      <ul class="nav navbar-nav navbar-right">
        <!-- <li class="dropdown"> -->
        <!-- <li>  </li> -->
        <!-- <li> </li> -->
        <!-- </li> -->
        <!-- <li>  </li> -->
        <!-- <li>  </li> -->

        <div class="dropdown">
          <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
            Login &amp; Join
            <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li role="presentation"><a href="/login" role="menuitem" tabindex="-1"><i class="fa fa-sign-in"></i> Login</a>
            </li>
            <li role="presentation"><a href="/register" role="menuitem" tabindex="-1"><i class="fa fa-sign-out"></i> Join</a>
            </li>
          </ul>
        </div>
      </ul>
    </div>
    <!-- /dropdown-parent-div -->

    <!-- /search-box-parent -->


    <div class="hidden-sm hidden-xs col-md-4 col-lg-4 masthead-group-2">
      <div class="input-group">
        <div class="input-group-btn search-panel">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <span id="search_concept">Filter by</span>  <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#contains">Contains</a>
            </li>
            <li><a href="#its_equal">It's equal</a>
            </li>
            <li><a href="#greather_than">Greather than &gt;</a>
            </li>
            <li><a href="#less_than">Less than &lt; </a>
            </li>
            <li class="divider"></li>
            <li><a href="#all">Anything</a>
            </li>
          </ul>
        </div>
        <input type="hidden" name="search_param" value="all" id="search_param">
        <input type="text" class="form-control" name="x" placeholder="Search term...">
        <span class="input-group-btn">
                    <button class="btn btn-default" type="button"><span class="fa fa-search"></span>
        </button>
        </span>
      </div>
    </div>
    <div class="hidden-sm hidden-xs col-md-3 col-lg-3 masthead-group-3">
      <!-- <div id="togglesidebar" class="btn btn-primary pull-right">
        <i class="fa fa-bars"></i>
      </div> -->

      <div id="togglesidebar" class="pull-right">
        <button class="btn btn-default btn-lg btn-primary"><i class="fa fa-child"></i> Submit News</button>
      </div>
    </div>



  </div>
  <div class="row clearfix">
    <div class="col-xs-12 col-sm-6 hidden-md hidden-lg masthead-group-2">
      <div class="input-group">
        <div class="input-group-btn search-panel">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <span id="search_concept">Filter by</span>  <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#contains">Contains</a>
            </li>
            <li><a href="#its_equal">It's equal</a>
            </li>
            <li><a href="#greather_than">Greather than &gt;</a>
            </li>
            <li><a href="#less_than">Less than &lt; </a>
            </li>
            <li class="divider"></li>
            <li><a href="#all">Anything</a>
            </li>
          </ul>
        </div>
        <input type="hidden" name="search_param" value="all" id="search_param">
        <input type="text" class="form-control" name="x" placeholder="Search term...">
        <span class="input-group-btn">
                    <button class="btn btn-default" type="button"><span class="fa fa-search"></span>
        </button>
        </span>
      </div>
    </div>
    <div class="col-xs-12 col-sm-6 hidden-md hidden-lg masthead-group-3">
      <!-- <div id="togglesidebar" class="btn btn-primary pull-right">
        <i class="fa fa-bars"></i>
      </div> -->

      <div id="togglesidebar" class="pull-right">
        <button class="btn btn-default btn-lg btn-primary"><i class="fa fa-child"></i> Submit News</button>
      </div>
    </div>
  </div>
  <!-- /row -->
</header>

答案 1 :(得分:0)

查看此内容并根据

修改源代码

<强> http://getbootstrap.com/components/#navbar

你可以这样做,在移动设备上更好看。

<nav class="navbar navbar-default" 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="#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="#">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</a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li 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">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>