html - 在滚动页面中创建固定 float 的div

标签 html css

在这个例子中,我需要黄色的 div 来保持固定而不是随着页面滚动。和红色的 div 显示在黄色 div 下方,中间有一些空白。当红色 div 滚动时,它应该在黄色 div 下方滚动,并且黄色和红色 div 之间应该有空白。请帮忙解决这个问题。

.fixspan
{
    width:100%;
    position:fixed;
    background-color:yellow;
}
.scrollingdiv
{
    background-color:red;
}
<div class='fixspan'>
    <span>This should not scroll with the page.</span>
</div>
<div class='scrollingdiv'>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
    <p>This is to expand content of the page</p>
</div>

最佳答案

this你在找什么?

CSS:

.fixspan {
  width: 100%;
  position: fixed;
  background-color: yellow;
  position: fixed;
  right: 0;
  top: 0;
  width: 10%;
  height: 100px;
}

.scrollingdiv {
  background-color: red;
  width: 88%;
}

我刚刚添加了顶部、右侧、宽度和高度属性。否则你的黄色不知道它应该“停留”在哪里。

关于html - 在滚动页面中创建固定 float 的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31940398/

相关文章:

html - CSS 背景图像未加载,但在我检查后加载

javascript - 如何在滚动窗口时转到另一个带有动画的页面?

javascript - jQuery:如何检查两个元素是否具有相同的类

javascript - 创建一个仅作为容器(没有其他功能)的 div(或其他元素)

jquery - 是否可以增加文本字段中字符之间的水平间距?

javascript - Nodejs EJS 中的循环

asp.net - 图像在 VS 设计模式中显示,但在浏览器中不显示

css - 在另一边展开搜索栏?

html - 在缩放的 html 主体上使用 Canvas

html - 导航栏在网页顶部时更改大小