html - 如何锁定 div 使其在滚动时不会移动

标签 html css

我遇到了一个问题,但找不到解决方案。我有一个包含 3 行文本的 div

<div class="Text">
    <h1>Hi</h1>
    <h2>I'm John Doe</h2>
    <h3>Param para param</h3>
</div>    

另外我添加了 div 所以我可以滚动

<div id="1" style="min-height:1000px;"></div>
<div id="2" style="min-height:1000px;" ></div>

请告诉我如何用文本锁定 div,这样当我滚动时它就不会移动

PS: position:fixed - doesn't work

最佳答案

我使用了 position:fixed 属性,当我们滚动时 div 不会移动,尝试使用代码片段

.text {
    position: fixed;
    top: 10%;
    left: 15%;
}
<div class="text" >
    <h1>Hi</h1>
    <h2>I'm John Doe</h2>
    <h3>Param para param</h3>
</div>

<div id="1" style="min-height:1000px;width:100%; background:#f1f1f1;"></div>
<div id="2" style="min-height:1000px;width:100%; background:#ddd;" ></div>

关于html - 如何锁定 div 使其在滚动时不会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41805571/

相关文章:

javascript - jQuery - 代码检查是否有任何字段不为空,然后将所有字段设为必填

javascript - 使用 AJAX 请求时还需要 Form 元素吗?

javascript - Twitter Bootstrap 模态窗口阴影未关闭

CSS:将菜单的链接右对齐

css - SASS - 在 :hover 时将转换器应用于::after

html - 如何相对于主要内容区域而不是窗口定位固定框?

javascript - 音频无法播放 - JS -

php - 如何使用我的 PHP 脚本中的数据动态更新 Bootstrap 进度条?

javascript - 打印时底部的页脚

html - 边框颜色 - Chrome 错误,还是我瞎了?