调整大小或移动时折叠侧边栏

时间:2013-06-19 02:08:53

标签: twitter-bootstrap

我希望以与顶栏相同的方式折叠侧栏(折叠+按钮)。

到目前为止,我在屏幕调整大小时出现了按钮。但是,它不会扩展内容上方的侧边栏。我点击按钮,没有任何事情发生。

这是我的源文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
    padding-top: 60px;
    padding-bottom: 40px;
}

.sidebar-nav {
    padding: 9px 0;
}

@media ( max-width : 980px) { /* Enable use of floated navbar text */
    .navbar-text.pull-right {
        float: none;
        padding-left: 5px;
        padding-right: 5px;
    }
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="assets/js/html5shiv.js"></script>
    <![endif]-->

<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144"
    href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
    href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
    href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed"
    href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>

<body>

    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container-fluid">No menu here...</div>
        </div>
    </div>

    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span3">
                <button type="button" class="btn btn-navbar"
 data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <div class="nav-collapse collapse">
                    <div class="sidebar-nav">
                        <ul class="nav nav-list">
                            <li class="nav-header">Sidebar</li>
                            <li class="active"><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li class="nav-header">Sidebar</li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li class="nav-header">Sidebar</li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                            <li><a href="#">Link</a></li>
                        </ul>
                    </div>
                    <!--nav collapse -->
                </div>
                <!--/.span3 -->
            </div>
            <!--/span-->
            <div class="span9">
                <h1>Content in here...</h1>
            </div>
        </div>
        <!--/row-->

        <hr>

        <footer>
            <p>&copy; Company 2013</p>
        </footer>

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

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="assets/js/jquery.js"></script>
    <script src="assets/js/bootstrap-transition.js"></script>
    <script src="assets/js/bootstrap-alert.js"></script>
    <script src="assets/js/bootstrap-modal.js"></script>
    <script src="assets/js/bootstrap-dropdown.js"></script>
    <script src="assets/js/bootstrap-scrollspy.js"></script>
    <script src="assets/js/bootstrap-tab.js"></script>
    <script src="assets/js/bootstrap-tooltip.js"></script>
    <script src="assets/js/bootstrap-popover.js"></script>
    <script src="assets/js/bootstrap-button.js"></script>
    <script src="assets/js/bootstrap-collapse.js"></script>
    <script src="assets/js/bootstrap-carousel.js"></script>
    <script src="assets/js/bootstrap-typeahead.js"></script>

</body>
</html>

这是我的补丁文件,表明对bootstrap CSS文件所做的更改。我主要通过在任何这些样式之前添加.btn-navbar来为.bavn-navbar添加相同的样式.navbar .btn-navbar。

diff --git a/assets/css/bootstrap-responsive.css b/assets/css/bootstrap-responsive.css
--- a/assets/css/bootstrap-responsive.css
+++ b/assets/css/bootstrap-responsive.css
@@ -1092,7 +1092,7 @@
     height: 0;
     overflow: hidden;
   }
-  .navbar .btn-navbar {
+  .btn-navbar, .navbar .btn-navbar {
     display: block;
   }
   .navbar-static .navbar-inner {



diff --git a/assets/css/bootstrap.css b/assets/css/bootstrap.css
--- a/assets/css/bootstrap.css
+++ b/assets/css/bootstrap.css
@@ -4631,7 +4631,7 @@
           box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
 }

-.navbar .btn-navbar {
+.btn-navbar, .navbar .btn-navbar {
   display: none;
   float: right;
   padding: 7px 10px;
@@ -4656,6 +4656,12 @@
           box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.075);
 }

+.btn-navbar:hover,
+.btn-navbar:focus,
+.btn-navbar:active,
+.btn-navbar.active,
+.btn-navbar.disabled,
+.btn-navbar[disabled],
 .navbar .btn-navbar:hover,
 .navbar .btn-navbar:focus,
 .navbar .btn-navbar:active,
@@ -4667,12 +4673,14 @@
   *background-color: #d9d9d9;
 }

+.btn-navbar:active,
+.btn-navbar.active, 
 .navbar .btn-navbar:active,
 .navbar .btn-navbar.active {
   background-color: #cccccc \9;
 }

-.navbar .btn-navbar .icon-bar {
+.btn-navbar .icon-bar, .navbar .btn-navbar .icon-bar {
   display: block;
   width: 18px;
   height: 2px;

我的目标是在我使用它之后将它们移到我的自定义CSS中。

对于.btn,jQuery文件看起来很简单,没有看到任何需要更改的内容。

1 个答案:

答案 0 :(得分:0)

哦,对于皮特的缘故......

我刚注意到这些错误:

“Uncaught TypeError: Object [object Object] has no method ‘on’ 

稍后快速搜索,我找到了这篇可爱的博文: http://brainmachine.mozganostroj.com/2012/05/04/catch-me-if-you-can-uncaught-typeerror-undefined-twitter-bootstrap-and-lodgrefine/

我下载了jQuery和voilà的最新副本!一切正常......叹息。