如何创建响应式菜单(汉堡菜单)

时间:2016-03-30 13:42:01

标签: javascript jquery html css twitter-bootstrap

嘿我有一个菜单,它是一个标签列表,每个标签使用一条垂直线与另一个标签分开。我试图弄清楚如何使这个菜单更具响应性,例如制作某种汉堡包菜单。到目前为止,我没有成功,因为我不熟悉在没有引导程序的情况下很好地制作响应组件的原则。 代码在这里



.tabs {
    padding: 0;
}

.tabs > li {
    list-style-type: none;
    display: inline-block;
    height: 25px;
    line-height: 25px;
    padding:0px 15px  ;
    color: #535355; 	
    font-size: 18px;
    font-family:'Segue UI', Calibri, arial, verdana, sans-serif;
    font-weight:bold;
    text-decoration: none;
    vertical-align: top;
    cursor: pointer;
    border-right: 1px solid #D1D1D1;
}

.tabs > li:last-child{
    border-right:none;
}

.tabs-link{
    color: #4C4C4C;     
    font-size: 18px;
    text-decoration: none;
}

.tabs-link:hover,
.tabs-link:link{
    color: #3983C4;      
    text-decoration: none;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav id="tabs_navbar" class="navbar navbar-collapse">
    <ul class="tabs">
        <!-- tabs navbar-->
        <li class="tabs-item">
            <a href="#/AnalyticsSummary" class="tabs-link">Analytics Summary</a>
        </li>
        <li class="tabs-item">
            <a href="#/TDCG" class="tabs-link">TDCG</a>
        </li>
        <li class="tabs-item">
            <a href="#/keygas" class="tabs-link">Key Gas</a>
        </li>
        <li class="tabs-item">
            <a href="#/DuvalTriangle" class="tabs-link">Duval Triangle</a>
        </li>
        <li class="tabs-item">
            <a href="#/DuvalPentagon" class="tabs-link">Duval Pentagon</a>
        </li>
        <li class="tabs-item">
            <a href="#/NEI" class="tabs-link">NEI</a>
        </li>
        <li class="tabs-item">
            <a href="#/PTX" class="tabs-link">PTX</a>
        </li>
        <li class="tabs-item">
            <a href="#/GasTrends" class="tabs-link">Gas Trends</a>
        </li>
        <li class="tabs-item">
            <a href="#/DataTable" class="tabs-link">Data Table</a>
        </li>
        <li class="tabs-item">
            <a href="#/Playground" class="tabs-link">Playground</a>
        </li>
        <li class="tabs-item">
            <a href="#/AnalyticsSettings" class="tabs-link">Analytics Settings</a>
        </li>
    </ul>
</nav>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:2)

您可以在css中使用@media个查询。

他们允许您为不同的屏幕尺寸定义不同的样式。 通常你会定义一些网站行为不同的断点。

结帐Using media queriesResponsive Menu Concepts 了解更多信息

这是展示基本构思的very basic example on JSFiddle,尝试调整视图大小以查看菜单更改布局模式。将鼠标悬停在“汉堡包”模式下的绿色框上以查看菜单

答案 1 :(得分:2)

如果您使用的是Bootstrap,请尝试以下代码:

<nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <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 id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Contact</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 class="dropdown-header">Nav header</li>
              <li><a href="#">Separated link</a></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="./">Default <span class="sr-only">(current)</span></a></li>
          <li><a href="../navbar-static-top/">Static top</a></li>
          <li><a href="../navbar-fixed-top/">Fixed top</a></li>
        </ul>
      </div><!--/.nav-collapse -->
    </div><!--/.container-fluid -->
  </nav>

答案 2 :(得分:0)

以下测试和工作

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Bootstrap Navigation Menu</title>
        <!-- Latest compiled and minified CSS -->
        <link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <!-- Optional theme -->
        <link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
    </head>
    <body>
        <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>
        <!-- Latest compiled and minified JavaScript -->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    </body>
</html>