2012-04-25 11 views
2

私はtwitterブートストラップを使用しています。ナビゲーションバーは折りたたみ機能でうまく動作します。subnavバーがtwitterブートストラップで折りたたまれた

これは私のhtmlコードです:

<div class="subnav"> 
    <ul class="nav nav-pills"> 
     <li class="dropdown"> 
     <a href="#" data-toggle="dropdown" class="dropdown-toggle">Buttons <b class="caret"></b></a> 
     <ul class="dropdown-menu"> 
      <li class=""><a href="#buttonGroups">Button groups</a></li> 
      <li class=""><a href="#buttonDropdowns">Button dropdowns</a></li> 
     </ul> 
     </li> 
     <li class="dropdown"> 
     <a href="#" data-toggle="dropdown" class="dropdown-toggle">Navigation <b class="caret"></b></a> 
     <ul class="dropdown-menu"> 
      <li class=""><a href="#navs">Nav, tabs, pills</a></li> 
      <li class=""><a href="#navbar">Navbar</a></li> 
      <li class=""><a href="#breadcrumbs">Breadcrumbs</a></li> 
      <li class=""><a href="#pagination">Pagination</a></li> 
     </ul> 
     </li> 
     <li class=""><a href="#labels">Labels</a></li> 
     <li class=""><a href="#badges">Badges</a></li> 
     <li class=""><a href="#typography">Typography</a></li> 
     <li class=""><a href="#thumbnails">Thumbnails</a></li> 
     <li class=""><a href="#alerts">Alerts</a></li> 
     <li><a href="#progress">Progress bars</a></li> 
     <li><a href="#misc">Miscellaneous</a></li> 
    </ul> 
    </div> 

は、これは私のbootstrap_and_overrides.css.scss

$iconSpritePath: asset-url('glyphicons-halflings.png', image); 
$iconWhiteSpritePath: asset-url('glyphicons-halflings-white.png', image); 
@import "bootstrap"; 
body { padding-top: 40px; 
     .navbar .brand {padding: 10px 20px; } 
     background: url("background.png") repeat scroll 0 0 #EEEEEE; 


.subnav { 
    background-color: #EEEEEE; 
    background-repeat: repeat-x; 
    border: 1px solid #E5E5E5; 
    border-radius: 4px 4px 4px 4px; 
    height: 36px; 



      .nav > li > a { 
         border-left: 1px solid #F5F5F5; 
         border-radius: 0 0 0 0; 
         border-right: 1px solid #E5E5E5; 
         margin: 0; 
         padding-bottom: 11px; 
         padding-top: 11px; 
         } 
    } 

    .subnav-fixed { 
    /*important part*/ 
    left: 0; 
    position: fixed; 
    right: 0; 
    top: 40px; 
    z-index: 1020; 
    /*design stuff*/ 
    border-color: #D5D5D5; 
    border-radius: 0 0 0 0; 
    border-width: 0 0 1px; 
    box-shadow: 0 1px 0 #FFFFFF inset, 0 1px 5px rgba(0, 0, 0, 0.1); 
    background-color: #FFFFFF; 
    } 
} 
@import "bootstrap-responsive"; 

であり、これは私のjsのコードです:

$(document).scroll(function(){ 
    // If has not activated (has no attribute "data-top" 
    if (!$('.subnav').attr('data-top')) { 
     // If already fixed, then do nothing 
     if ($('.subnav').hasClass('subnav-fixed')) return; 
     // Remember top position 
     var offset = $('.subnav').offset() 
     $('.subnav').attr('data-top', offset.top); 
    } 

    if ($('.subnav').attr('data-top') - $('.subnav').outerHeight() <= $(this).scrollTop()) 
     $('.subnav').addClass('subnav-fixed'); 
    else 
     $('.subnav').removeClass('subnav-fixed'); 
}); 

また、私はサブナブバーを使用しています、私の問題は私のサブナブバーが崩壊していないことです。

Twitterのブートストラップで正しいsubnavバーバージョン:

fine subnav twitter bootstrap

それが正常に動作しません私の悪いバージョン:/

bad subnav twitter bootstrap

どのようにすることができますこの問題を解決しますか?

ありがとうございました!

+0

コードを入力できますか?ライブ作業のデモが最高ですが、少なくともあなたのメニューにHTMLとCSSを提供してください。コードを見ることなく、あなたは野生の推測しか得られません。 – Jrod

+0

ありがとうJrod、コードhtml、css、jsを追加しました:D – hyperrjas

+0

@Jrod答えでこの問題の修正を追加しました。よろしく! – hyperrjas

答えて

2

あなたはこの問題を持っている場合、あなたはこの本で問題解決することができます:あなたのCSSファイルで、ファイル

//subnav config 
$(function(){ 

    var $win = $(window); 
    var $nav = $('.subnav'); 
    var navTop = $('.subnav').length && $('.subnav').offset().top - 38; 
    var isFixed = 0; 

    processScroll(); 

    $win.on('scroll', processScroll); 

    function processScroll() { 
     console.log('test'); 
     var i, scrollTop = $win.scrollTop(); 
     if (scrollTop >= navTop && !isFixed) { 
      isFixed = 1; 
      $nav.addClass('subnav-fixed'); 
     } else if (scrollTop <= navTop && isFixed) { 
      isFixed = 0; 
      $nav.removeClass('subnav-fixed'); 
     } 
    }; 
}) 

:あなたはこのjqueryのコードを追加する必要がありますjavascriptのファイルあなた

をbootstrap_and_overrides.css.scssあなたはこのコードを追加することができます

/* Add additional stylesheets below 
-------------------------------------------------- */ 

/* Subnav */ 
.subnav { 
    width: 100%; 
    height: 36px; 
    background-color: #eeeeee; /* Old browsers */ 
    background-repeat: repeat-x; /* Repeat the gradient */ 
    background-image: -moz-linear-gradient(top, #f5f5f5 0%, #eeeeee 100%); /* FF3.6+ */ 
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f5f5f5), color-stop(100%,#eeeeee)); /* Chrome,Safari4+ */ 
    background-image: -webkit-linear-gradient(top, #f5f5f5 0%,#eeeeee 100%); /* Chrome 10+,Safari 5.1+ */ 
    background-image: -ms-linear-gradient(top, #f5f5f5 0%,#eeeeee 100%); /* IE10+ */ 
    background-image: -o-linear-gradient(top, #f5f5f5 0%,#eeeeee 100%); /* Opera 11.10+ */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f5f5f5', endColorstr='#eeeeee',GradientType=0); /* IE6-9 */ 
    background-image: linear-gradient(top, #f5f5f5 0%,#eeeeee 100%); /* W3C */ 
    border: 1px solid #e5e5e5; 
    -webkit-border-radius: 4px; 
    -moz-border-radius: 4px; 
      border-radius: 4px; 
} 
.subnav .nav { 
    margin-bottom: 0; 
} 
.subnav .nav > li > a { 
    margin: 0; 
    padding-top: 11px; 
    padding-bottom: 11px; 

    border-right: 1px solid #e5e5e5; 
    -webkit-border-radius: 0; 
    -moz-border-radius: 0; 
      border-radius: 0; 
} 
.subnav .nav > .active > a, 
.subnav .nav > .active > a:hover { 
    padding-left: 13px; 
    color: #777; 
    background-color: #e9e9e9; 
    border-right-color: #ddd; 
    border-left: 0; 
    -webkit-box-shadow: inset 0 3px 5px rgba(0,0,0,.05); 
    -moz-box-shadow: inset 0 3px 5px rgba(0,0,0,.05); 
      box-shadow: inset 0 3px 5px rgba(0,0,0,.05); 
} 
.subnav .nav > .active > a .caret, 
.subnav .nav > .active > a:hover .caret { 
    border-top-color: #777; 
} 
.subnav .nav > li:first-child > a, 
.subnav .nav > li:first-child > a:hover { 
    border-left: 0; 
    padding-left: 12px; 
    -webkit-border-radius: 4px 0 0 4px; 
    -moz-border-radius: 4px 0 0 4px; 
      border-radius: 4px 0 0 4px; 
} 
.subnav .nav > li:last-child > a { 
    border-right: 0; 
} 
.subnav .dropdown-menu { 
    -webkit-border-radius: 0 0 4px 4px; 
    -moz-border-radius: 0 0 4px 4px; 
      border-radius: 0 0 4px 4px; 
} 


/* Fixed subnav on scroll, but only for 980px and up (sorry IE!) */ 
@media (min-width: 980px) { 
    .subnav-fixed { 
    position: fixed; 
    top: 40px; 
    left: 0; 
    right: 0; 
    z-index: 1020; /* 10 less than .navbar-fixed to prevent any overlap */ 
    border-color: #d5d5d5; 
    border-width: 0 0 1px; /* drop the border on the fixed edges */ 
    -webkit-border-radius: 0; 
     -moz-border-radius: 0; 
      border-radius: 0; 
    -webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1); 
     -moz-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1); 
      box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1); 
    filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); /* IE6-9 */ 
    } 
    .subnav-fixed .nav { 
    width: 100%; 
    margin: 0 auto; 
    padding: 0 1px; 
    background-color: #FFFFFF; 
    } 
    .subnav .nav > li:first-child > a, 
    .subnav .nav > li:first-child > a:hover { 
    -webkit-border-radius: 0; 
     -moz-border-radius: 0; 
      border-radius: 0; 
    } 
} 


@media (max-width: 768px) { 

    /* Subnav */ 
    .subnav { 
    position: static; 
    top: auto; 
    z-index: auto; 
    width: auto; 
    height: auto; 
    background: #fff; /* whole background property since we use a background-image for gradient */ 
    -webkit-box-shadow: none; 
     -moz-box-shadow: none; 
      box-shadow: none; 
    } 
    .subnav .nav > li { 
    float: none; 
    } 
    .subnav .nav > li > a { 
    border: 0; 
    } 
    .subnav .nav > li + li > a { 
    border-top: 1px solid #e5e5e5; 
    } 
    .subnav .nav > li:first-child > a, 
    .subnav .nav > li:first-child > a:hover { 
     -webkit-border-radius: 4px 4px 0 0; 
     -moz-border-radius: 4px 4px 0 0; 
       border-radius: 4px 4px 0 0; 
    } 


} 

場合このコードはあなたのために有効です。答えを受け入れて、この応答に肯定的なフィードバックを与えてください。私は助けて欲しい。

ありがとうございました。