2017-07-20 113 views
0

我有一個垂直導航欄,用作我的asp.net MVC5項目中的一個菜單。在一個css樣式表中,我定義了它是position:fixed;能夠一直看到它。在我的網頁的另一部分,我有一個根據菜單選擇而改變的局部視圖。我的問題是,當局部視圖太大時,當我水平滾動查看缺少的內容時,文本與導航欄重疊。正在瀏覽導航欄的文本

這裏是我的導航欄樣品中一個名爲_Menu.cshtml

<div class="sidebar-nav"> 
    <div class="navbar navbar-default" role="navigation"> 
     <div class="navbar-header"> 
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-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> 
      <span class="visible-xs navbar-brand">Sidebar menu</span> 
     </div> 
     <div class="navbar-collapse collapse sidebar-navbar-collapse"> 
      <ul class="nav navbar-nav" id="sidenav01"> 
       <li class="active"> 
        <a href="#" data-toggle="collapse" data-target="#toggleDoc" data-parent="#sidenav01" class="collapsed"> 
         <span class="glyphicon glyphicon-folder-close"></span> Documentation <span class="caret pull-right"></span> 
        </a> 
        <div class="collapse" id="toggleDoc" style="height: 0px;"> 
         <ul class="nav nav-list"> 
          <li><a href="#">Documentation 1.1</a></li> 
          <li><a href="#">Documentation 1.2</a></li> 
          <li><a href="#">Documentation 1.3</a></li> 
         </ul> 
        </div> 
       </li> 
      </ul> 
     </div> 
    </div> 
</div> 

_Layout.cshtml,我有<body>標記中以下內容:

<div class="container-fluid"> 
    <div class="row affix-row"> 
     <div class="col-sm-4 col-md-4 col-lg-4 col-xl-4 affix-sidebar"> 
       @Html.Partial("~/Views/PartialViews/_Menu.cshtml") 
     </div> 
     <div class="col-sm-8 col-md-8 col-lg-8 col-xl-8"> 
       @RenderBody() 
     </div> 
    </div> 
</div> 

最後的CSS:

.sidebar-nav{ 
    position: fixed; //Center works but then my navbar is not fixed anymore! 
} 

我使用bootstrap分離e我的頁面的兩個部分,因此左邊有菜單,右邊是正文(或菜單鏈接的部分視圖)。我知道使導航條position不同將解決問題。但我想有一個固定的導航欄,這不會被水平固定有我的網頁的右側部分的文本後面的導航欄。任何想法如何做到這一點?

這裏是什麼樣子(注意IpAdress沒有顯示,所以頁面是不是真的滿了,請佩服我的繪畫技巧:P)enter image description here

+1

您是否嘗試過使用z-index的爲 「層」 你的菜單在你的內容? –

+0

你可以做小提琴嗎? –

+0

@KanstantsinArlouski不,我會檢查出來,謝謝,然後我把jsfiddle,如果它不工作:) –

回答

1

您可能需要使用z-index的嘗試,或者使用填充div,它將充當您的內容和菜單之間頂部的間隔符。下面的例子。

.sidebar-nav{ 
 
    position: fixed; //Center works but then my navbar is not fixed anymore! 
 
    width: 100%; 
 
    z-index: 1; 
 
} 
 
#filler { 
 
    display: block; 
 
    height: 50px; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="sidebar-nav"> 
 
    <div class="navbar navbar-default" role="navigation"> 
 
     <div class="navbar-header"> 
 
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-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> 
 
      <span class="visible-xs navbar-brand">Sidebar menu</span> 
 
     </div> 
 
     <div class="navbar-collapse collapse sidebar-navbar-collapse"> 
 
      <ul class="nav navbar-nav" id="sidenav01"> 
 
       <li class="active"> 
 
        <a href="#" data-toggle="collapse" data-target="#toggleDoc" data-parent="#sidenav01" class="collapsed"> 
 
         <span class="glyphicon glyphicon-folder-close"></span> Documentation <span class="caret pull-right"></span> 
 
        </a> 
 
        <div class="collapse" id="toggleDoc" style="height: 0px;"> 
 
         <ul class="nav nav-list"> 
 
          <li><a href="#">Documentation 1.1</a></li> 
 
          <li><a href="#">Documentation 1.2</a></li> 
 
          <li><a href="#">Documentation 1.3</a></li> 
 
         </ul> 
 
        </div> 
 
       </li> 
 
      </ul> 
 
     </div> 
 
    </div> 
 
</div> 
 
<div class="container-fluid"> 
 
    <div class="row affix-row"> 
 
     <div id="filler"></div> 
 
     <div iclass="col-sm-4 col-md-4 col-lg-4 col-xl-4 affix-sidebar"> 
 
       <!-- @Html.Partial("~/Views/PartialViews/_Menu.cshtml") --> 
 
       <p>Bunchotext</p> 
 
     </div> 
 
     <div class="col-sm-8 col-md-8 col-lg-8 col-xl-8"> 
 
       <!-- @RenderBody() --> 
 
       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam vitae semper tortor, non efficitur nulla. Pellentesque elementum augue arcu, quis fermentum elit vestibulum eu. Curabitur ornare volutpat turpis, vitae pellentesque ex commodo lacinia. Sed venenatis dui nisi, sed feugiat dui hendrerit a. Nullam rutrum libero at mauris pellentesque bibendum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vestibulum volutpat efficitur arcu, nec eleifend ante consectetur vitae. 
 

 
In hac habitasse platea dictumst. Ut ornare, nisl non pharetra ultricies, arcu sapien porttitor ligula, vitae pellentesque diam tellus vitae urna. Sed eget tempus orci, sit amet egestas nisl. Nam sed aliquet ex, vel consequat magna. Aliquam enim diam, sollicitudin ut metus ut, accumsan dictum nunc. Phasellus dictum ultrices leo, tempus elementum nisl commodo eu. Ut efficitur turpis id dui accumsan lobortis. Fusce semper venenatis orci in dapibus. Ut id dolor et diam sagittis mollis. Nam vulputate tincidunt enim, vel facilisis leo ultricies eget. Mauris accumsan at diam id imperdiet. Integer gravida, nisi eget accumsan consectetur, purus quam suscipit est, maximus ullamcorper lectus lorem non velit. In interdum nec lectus et luctus. Donec congue malesuada tellus, vel auctor magna egestas non. 
 

 
Nulla hendrerit, velit a euismod blandit, enim ex ultricies elit, ac aliquam massa tortor vitae erat. Mauris rutrum hendrerit nisl vel finibus. Sed aliquam eget arcu eget egestas. Nullam a auctor ante. Donec a nibh fringilla, ornare nibh ac, posuere felis. Pellentesque condimentum suscipit vestibulum. Fusce quis sapien non ex mattis ultricies et sit amet metus. Phasellus at nunc sollicitudin, tristique nunc eget, sodales augue. Praesent sagittis justo eget placerat feugiat. 
 

 
Fusce aliquet enim eget venenatis fringilla. Suspendisse imperdiet, tellus eu pretium fringilla, ligula ante fermentum dui, in venenatis erat risus nec erat. Curabitur libero dolor, semper eu eros sit amet, eleifend accumsan diam. Fusce dui ante, pellentesque vitae nisl at, dapibus consectetur arcu. Mauris rhoncus nisl nec leo sollicitudin, eu fermentum nisi sodales. Quisque magna dolor, consequat sed ultricies dignissim, ullamcorper eu dui. Fusce vitae est sed augue ornare finibus. Aenean a eleifend ipsum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc dapibus malesuada nulla ac dignissim. Nulla scelerisque diam vel neque consequat, tempus facilisis eros tempor. Ut pellentesque urna vitae tellus imperdiet, a sagittis ipsum condimentum. Nullam in purus ut nisl porttitor porttitor nec eget metus. Sed maximus nisl arcu. Suspendisse ut egestas ipsum, ut varius nisi. 
 

 
Nulla lacus neque, suscipit quis odio ac, accumsan molestie nisi. Vestibulum quam quam, bibendum non velit eu, faucibus laoreet sem. Aliquam auctor rhoncus ultrices. Nullam a sem sagittis, accumsan risus eu, auctor nisl. Nam vestibulum lobortis sagittis. Nunc vel ultricies sem, et convallis nulla. Mauris elementum imperdiet lorem, non maximus enim. Suspendisse dictum turpis massa, at bibendum neque ultrices ac. Sed sodales tempor augue et molestie. </p> 
 
     </div> 
 
    </div> 
 
</div>

+0

是的,填充物並不能解決問題,但它增加了一個空間,但我的問題是在一個垂直的立場上,所以我不能讓它工作。我想我給你的代碼片段是誤導性的,因爲通常情況下,菜單位於菜單的左側,文本位於菜單的右側(如果文本太長,它們只會重疊,而且必須滾動到右側,這是我認爲的另一個問題。 !)。再次感謝:) –

+0

我很樂意爲您提供幫助,您能爲我製作提琴手/ codepen嗎?這樣做,給我你的最終結果,它應該完成。 –

+1

哇,真的很親切:)我就在這!所以當我把它放在jsfiddle上時,沒有這個問題了! https://jsfiddle.net/oaq1m1ma/也許它來自幫手@RenderBody?在這個演示中,文本在調整大小時會受到擠壓,但是我的實際頁面沒有這樣做,我正在查看有什麼區別 –