2017-08-13 171 views
0

我有一个任务是建立一个边栏,其高度等于内容。 内容越多,侧边栏就越大。如何使边栏高度取决于内容高度?

实际上,我的侧栏等于窗口大小,而不是内容。如果我向下滚动页面,则没有侧栏。

这是我的代码:

HTML:

<div class = "container" style = "height :100%"> 
    <div class = "row" style = "height:100%"> 
    <div class = "col-md-3 hidden-xs hidden-sm" style = "height:100%"> 
     <div class = "sidebar"> 
     ......... 
    </div> 
    </div> 
</div> 
</div> 

CSS:

html .sidebar, 
body .sidebar { 
    height: 100%; 
    width: 100%; 
    background: black; 
} 

为什么?怎么做才能使它工作?

回答

0

如果我正确地得到你的意思,那么你希望边栏被修复?

为了做到这一点,你可以做一些有点像这样在CSS ..

.sidebar { 
 
    width: 250px; 
 
    height: 100vh; 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    background: black; 
 
}
<div class="sidebar"> 
 

 
</div>

+1

太感谢你了)一切正常) – Aleks339

+0

不用担心,请接受作为正确答案@ Aleks339 :) – tallent123