【问题标题】:How to make sidebar height to be dependent of the content height?如何使侧边栏高度依赖于内容高度?
【发布时间】:2017-08-13 12:49:45
【问题描述】:

我的任务是构建一个侧边栏,其高度等于内容之一。 内容越多,侧边栏越大。

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

这是我的代码:

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;
}

为什么?怎样做才能让它发挥作用?

【问题讨论】:

    标签: html css


    【解决方案1】:

    如果我理解你的意思,那么你想要修复侧边栏吗?

    为了做到这一点,你可以在 css 中做一些类似这样的事情..

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

    【讨论】:

    • 别担心,请采纳为正确答案@Aleks339 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多