2017-10-10 77 views
-1

我試圖使height: 100%;使用div,但背景需要有一個固定的位置。溢出-y不能使用固定位置

我試圖使用box-sizing:border-box;像某人回答類似我的問題,但這不適合我。此外,我試圖使用絕對位置,但仍然是一樣的。

這裏是我的CSS

.backgroundIdKlupa { 
position:fixed; 
padding: 0; 
z-index: 999999; 
margin-bottom: 45px; 
} 
.backgroundIdKlupa_tablica { 
background-color: grey; 
top: 0; 
bottom:0; 
position:fixed; 
overflow-y:scroll; 
overflow-x:hidden; 
} 
.idKlupa_tablica { 
height: 90%; 
font-size: 14px; 
font-weight: bold; 
margin-bottom: 45px; 
} 
.backgroundIda { 
background-color: green; 
width: 100%; 
height: 550px; 
} 

的Html

<div class="backgroundIdKlupa col-lg-1 col-md-1 col-sm-2 col-xs-12"> 
      <table class="backgroundIdKlupa_tablica table-hover"> 
       <thead> 
        <tr> 
         <th class="backgroundIdKlupa_izbornik_th">Bench ID</th> 
        </tr> 
       </thead> 
       <tbody> 
        <tr> 
        <td class="aktivniItem backgroundIdKlupa_izbornik_td" >123</td> 
        </tr> 
        <tr> 
        <td class="aktivniItem backgroundIdKlupa_izbornik_td" >123</td> 
        </tr> 
        <tr> 
        <td class="aktivniItem backgroundIdKlupa_izbornik_td" >123</td> 
        </tr> 
       </tbody> 
      </table> 
     </div> 
     <div class="backgroundIda col-lg-1 col-md-1 col-sm-2 col-xs-12"></div> 

左邊的菜單需要修復,但如果有更多的項目,需要有溢出-Y:汽車

權內容(綠色)是正常的。 Thnx

回答

1
For add scroll in any element you need to add height or max-height. second this is a table so make it a block element by using display:block 

backgroundIdKlupa_tablica { 
    background-color: grey; 
    top: 0; 
    bottom: 0; 
    position: fixed; 
    overflow-y: scroll; 
    overflow-x: hidden; 
    height: 50px; 
    display: block; 
} 
+0

謝謝你Ankit Awasthi。這項工作,但爲了身高,我需要增加身高:100%;但百分比不起作用。 – Arter

+1

.backgroundIdKlupa_tablica { \t \t \t \t background-color:gray; \t \t \t \t top:0; \t \t \t \t bottom:0; \t \t \t \t position:fixed; \t \t \t \t overflow-y:auto; \t \t \t \t overflow-x:hidden; \t \t \t \t身高:100%; \t \t \t \t display:block; \t \t \t \t}這裏工作對我來說只是補充充足行的表 –