HTML / CSS Div不会一直向下

问题描述 投票:0回答:2

我正在尝试创建一个带有静态侧栏和可滚动文本的网站。我无法真正找到为什么我的内容分隔符不会一直向下的原因。我也想知道是否更好的做法是使内容分割器固定或在最底层继续它。查看页面如何不适合灰色分隔符

Problem

到目前为止,这是我的代码:

HTML:

<div id="content">
    <div id="sidebar">
        <p>This is sidebar</p>
    </div>      
    <div id="page">
        <p>This is page</p>
        ...
    </div>
</div>

CSS:

#content {
    height: 100%;
    background-color: lightgrey;
    background-attachment: fixed;   /* THIS DOES NOT WORK */
    margin: auto;
    width: 80%;
}
#sidebar {  
    margin-top: 10%;
    text-align: right;
    position: fixed;
    bottom: 0;
    float: left;
    width: 34%;
    height: 70%;
}
#page {
    float: right;
    width: 54%;
}

附:我设法通过添加overflow:auto来解决这个问题。分页器,但我真的不喜欢页面上的滚动条。

html css scroll background-color fixed
2个回答
0
投票

我想在你的CSS中你也有html,body {height:100%}并通过将height:100%定义为你将内容限制为浏览器大小的内容,因此背景将不会继续,你将会溢出。使用min-height而不是高度。你也使用浮点数,所以你需要使用overflow:auto清除它

html,body {
  height: 100%;
}

#content {
  min-height:100%;
  overflow:auto;
  background-color: lightgrey;
  margin: auto;
  width: 80%;
}

#sidebar {
  margin-top: 10%;
  text-align: right;
  position: fixed;
  bottom: 0;
  float: left;
  width: 34%;
  height: 70%;
}

#page {
  float: right;
  width: 54%;
}
<div id="content">
  <div id="sidebar">
    <p>This is sidebar</p>
  </div>
  <div id="page">
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    <p>This is page</p>
    ...
  </div>
</div>

0
投票

我认为你应该使用min-height而不是height来拥有适合内容的灵活高度,如下所示:

#content {
min-height: 1000px;
}

我这样工作,每次你都应该尝试它,它与我合作。

© www.soinside.com 2019 - 2024. All rights reserved.