Navbar折叠在Bootstrap中无法正常工作

时间:2017-01-12 14:06:31

标签: html css asp.net-mvc twitter-bootstrap

这是我的mvc局部视图:

<nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.RouteLink("მთავარი", "AdminControlUsers", null, new { @class = "navbar-brand", @style="padding-left:100px; padding-right:100px"})//this line
            </div>
    <div class="collapse navbar-collapse" id="myNavbar">
                <ul class="nav navbar-nav">
                    @if (ViewBag.NavBarActive == "მომხმარებლები")
                    {
                        <li class="active">@Html.RouteLink("მომხმარებლები", "AdminControlUsers")</li>
                        <li>@Html.RouteLink("Stored Procedures", "ControlStoredProcedures", new { page = 1 })</li>
                        <li>@Html.RouteLink("გაშვებული Stored Procedure-ები", "Admin_User_Results_List")</li>
                    }
                    @if (ViewBag.NavBarActive == "Stored Procedures")
                    {
                        <li>@Html.RouteLink("მომხმარებლები", "AdminControlUsers")</li>
                        <li class="active">@Html.RouteLink("Stored Procedures", "ControlStoredProcedures", new { page = 1 })</li>
                        <li>@Html.RouteLink("გაშვებული Stored Procedure-ები", "Admin_User_Results_List")</li>
                    }
                    @if (ViewBag.NavBarActive == "User_Admin Results List")
                    {
                        <li>@Html.RouteLink("მომხმარებლები", "AdminControlUsers")</li>
                        <li>@Html.RouteLink("Stored Procedures", "ControlStoredProcedures", new { page = 1 })</li>
                        <li class="active">@Html.RouteLink("გაშვებული Stored Procedure-ები", "Admin_User_Results_List")</li>
                    }
                </ul>
                <ul class="nav navbar-nav navbar-right">
    li><a href='@Url.Action("LogOut", "Administrator")'><span class="glyphicon glyphicon-log-out"></span> გამოსვლა @Session["Admin"].ToString()</a></li>
                </ul>
            </div>
        </div>
    </nav>

当我调整浏览器大小时,我的导航栏截图: enter image description here

enter image description here

enter image description here enter image description here

当我删除其中一行时:

@Html.RouteLink("მთავარი", "AdminControlUsers", null, new { @class = "navbar-brand", @style="padding-left:100px; padding-right:100px"})

如果我删除@style =&#34; padding-left:100px;填充右:100px的&#34;它工作正常:/。请帮忙

2 个答案:

答案 0 :(得分:1)

内容比崩溃min-width更快地溢出,您需要将导航栏折叠按钮设置为先前显示。

您可以通过CSS完成此操作,在样式表上设置最后一个(根据您的需要调整max-width@media (min-width: 768px) and (max-width: 991px) { .navbar-collapse.collapse { display: none !important; } .navbar-collapse.collapse.in { display: block !important; } .navbar-header .collapse, .navbar-toggle { display:block !important; } .navbar-header { float:none; } } ):

           $image = new WP_Query( 
            array(
                'post_type' => 'attachment', 
                'media_category' => 'imgfront',
                'posts_per_page' => '1', 
                'orderby' => 'rand',   
                )
            );  

        if( $image->have_posts() ){
            $image_attributes = wp_get_attachment_image_src( $image->posts[0], 'full' );
            ?><img src="<?php echo $image_attributes[0]; ?>"> <?php
        }

Test it on this resizable external Fiddle

enter image description here

答案 1 :(得分:0)

你在这里:

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>

  <nav id="menu" class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header">
        <a class="navbar-brand" href="#">WebSiteName</a>
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span> 
        </button>
      </div>
      <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a>
          </li>
          <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Page 1-1</a>
              </li>
              <li><a href="#">Page 1-2</a>
              </li>
              <li><a href="#">Page 1-3</a>
              </li>
            </ul>
          </li>
          <li><a href="#">Page 2</a>
          </li>
          <li><a href="#">Page 3</a>
          </li>
        </ul>        
      </div>
    </div>
  </nav>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
  <p>abc</p>
</body>

</html>
&#13;
&#13;
&#13;