javascript - 位置 :absolute div inside another position:absolute div and making them position:fixed

标签 javascript jquery html css

HTML

<div class="div1"></div>
<div class="div2">
  <div class="div3"></div>
</div>

CSS

div1、div2 和 div3 的属性是:

 div1. {
   position: absolute;
   z-index: 100;
   background-color: rgba(39, 39, 39, 0.3);
   height: 90px;
   width: 712px;
   left: 0px;
   bottom: 216px;
}

.div2 {
  position: relative;
}

.div3 {
  position: absolute;
  bottom: 263px;
  margin-left: 50px;
}

现在根据我的概念,div1 是绝对的,我应该将 div3 设置为绝对的,从而将它放在 div1 中。现在我的问题是我需要将 div1 设置为 position:fixed 如果我滚动它它应该在那里但是如果我给出这样的 div 3 不是固定的并且它正在移动。我可以得到这个的棘手点吗

最佳答案

将 div1 和 div3 的位置更改为固定,滚动时它们将保持不变。 div1 的 CSS 中还有一个小错字(句点放在“div1”之后而不是之前)。

.div1 {
   position: fixed;
   z-index: 100;
   background-color: rgba(39, 39, 39, 0.3);
   height: 90px;
   width: 712px;
   left: 0px;
   bottom: 216px;
}

.div2 {
  position: relative;
}

.div3 {
  position: fixed;
  bottom: 263px;
  margin-left: 50px;
}

关于javascript - 位置 :absolute div inside another position:absolute div and making them position:fixed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22319276/

相关文章:

javascript - 选择选项后触发 'click'?

jquery - 使用 jQuery 和 Ajax 启动 Bootstrap Modal 后,单击事件处理程序会多次发生

javascript - 如何将 `$(this)` 作为参数传递给 Javascript 中的 "callready"函数

html - 使用 CSS 清除 <select> 元素的下拉按钮的背景

html - 使 flex 元素在悬停时展开,缩小其 sibling

javascript - 错误 [ERR_MODULE_NOT_FOUND] : Cannot find package 'src'

javascript - 多个 "if"语句

javascript - 在 Javascript 中单击按钮删除表格行

javascript - PouchDB:创建用于获取唯一键的设计文档

javascript - 如何测试 JavaScript 代码的性能?