使用Bootstrap的响应式菜单

问题描述 投票:-2回答:3

可以任何人帮助我使用Bootstrap CSS创建菜单每个引导菜单的教程都没有完全满足我的要求所以请任何人告诉我如何创建响应式菜单

图像包含两个图像1用于普通浏览器,另一个图像用于移动

我试过以下代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Twitter Bootstrap 3 Static Navbar Extended</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
     <style type="text/css">
         .bs-example{
        margin: 20px;
            }
     </style>
<script>

</script>
</head> 
<body>
<div class="bs-example">
    <nav role="navigation" class="navbar navbar-default">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
           <!--  <a href="#" class="navbar-brand">Brand</a> -->
        </div>
        <!-- Collection of nav links, forms, and other content for toggling -->
        <div id="navbarCollapse" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a>                </li>
                <li><a href="#">Profile</a></li>
                <li><a href="#">Login</a></li>
              </ul>
            <!-- <ul class="nav navbar-nav">
                <li><a href="#">Login</a></li>
            </ul> -->
        </div>
    </nav>
</div>
</body>
</html>
javascript jquery html5 twitter-bootstrap responsive-design
3个回答
0
投票

你查过这些例子了吗?

完全按照你的需要做

此外,this实用程序允许您创建引导导航栏

UPDATE

JSFIDDLE

<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="test">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".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>
      <a class="navbar-brand" href="#link1" style="display:none;" id="link">item 1</a>
    </div>
    <div class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#link1">item 1</a></li>
        <li><a href="#link2">item 2</a></li>
        <li><a href="#link2">item 3</a></li>

      </ul>

    </div>
  </div>
</div>


$(document).ready(function() {

//control for the creation
if($(window).width() < 767){
       $("#link").show();
    }

});

$(document).load($(window).bind("resize", do_menu));

function do_menu(){

   if($(window).width() < 767){
      $("#link").show();
   }else{
       $("#link").hide();
   }

}

0
投票

我已经修改了twitter bootstrap HTML代码,我相信下面的解决方案与你期望的非常接近

<!-- Static navbar -->
      <div class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".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>
            <a class="navbar-brand hidden-lg" href="#" data-toggle="dropdown">Project name</a>
          </div>
          <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">1 First Topic</a></li>
              <li><a href="#">1 First Topic</a></li>
              <li><a href="#">1 First Topic</a></li>

            </ul>

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

0
投票

我得到了我的解决方案:以下是我需要的代码:

                    <!DOCTYPE html>
                    <html lang="en">
                    <head>
                    <meta charset="UTF-8">
                    <title>Example of Twitter Bootstrap 3 Static Navbar Extended</title>
                    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
                    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
                    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
                    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
                    <style type="text/css">
                        .bs-example{
                            margin: 20px;
                        }
                    </style>
                    <script>
                      $(document).ready(function(){

                                $(window).resize(function(){

                                    console.log($(window).width());
                                    if($(window).width()<767)
                                    {
                                        $(".navbar-brand").html($(".active>a").text());
                                    }
                                    else
                                    {
                                        $(".navbar-brand").html("");
                                    }

                                });

                                $("ul>li").click(function(){

                                        //alert($(this).find("a").text());
                                        $(".active").removeClass("active");
                                        $(this).addClass("active");
                                        if($("#navbarCollapse").hasClass("in"))
                                        {
                                            $("#navbarCollapse").removeClass("in")
                                            $("#navbarCollapse").addClass("collapse")
                                        }

                                        if($(window).width()<767)
                                        {
                                            $(".navbar-brand").html($(".active>a").text());
                                        }
                                        else
                                        {
                                            $(".navbar-brand").html("");
                                        }


                                });
                      });
                    </script>
                    </head> 
                    <body>
                    <div class="bs-example">
                        <nav role="navigation" class="navbar navbar-default">
                            <!-- Brand and toggle get grouped for better mobile display -->
                            <div class="navbar-header">
                                <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                                    <span class="sr-only">Toggle navigation</span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                                <a href="#" class="navbar-brand"></a>  
                            </div>
                            <!-- Collection of nav links, forms, and other content for toggling -->
                            <div id="navbarCollapse" class="collapse navbar-collapse">
                                <ul class="nav navbar-nav">
                                    <li class="active"><a href="#">Home</a></li>
                                    <li><a href="#">Profile</a></li>
                                    <li><a href="#">Login</a></li>
                                  </ul>
                            </div>
                        </nav>
                    </div>
                    </body>
                    </html>                                     
© www.soinside.com 2019 - 2024. All rights reserved.