jquery - 为什么我的 CSS 底部属性将 div 的顶部边缘与文档底部对齐,而不是底部边缘?
问题描述
我正在尝试将图像幻灯片放在页脚的正上方,滑块的底部边缘粘在页脚的顶部边缘。但是当我使用 position: fixed, bottom: 0 属性时,它看起来像是将顶部边缘与页面底部对齐。为什么会这样?
我试过位置:固定,底部:0;并将幻灯片 div 发送到页面底部(div 实际上消失了,因为它似乎贴在顶部边缘而不是底部边缘)。
.slideshow {
position: fixed;
bottom: 0px;
width: 100%;
padding-bottom: 85px;
}
.footer {
position: fixed;
bottom: 0;
background: #0d9196;
width: 100%;
height: 80px;
}
我希望这两个 div 是堆叠的,但实际上它只是将整个幻灯片 div 从页面底部发送出去,隐藏在页脚下方。帮助!
解决方案
具有位置的元素:固定;相对于视口定位
这就是当你给bottom:0
你的元素时,它们都堆叠在你的页面底部(视口)相互重叠的原因。
请position:fixed
参阅https://www.w3schools.com/css/css_positioning.asp
如果您希望它们堆叠,
bottom: 80px(height of your footer)
请向您的.slideshow
.slideshow {
position: fixed;
bottom: 80px;
width: 100%;
padding-bottom: 85px;
background: #ff0000;
}
.footer {
position: fixed;
bottom: 0;
background: #0d9196;
width: 100%;
height: 80px;
}
<div class="slideshow"></div>
<div class="footer"></div>
替代解决方案:
将父级添加到两者divs
并像这样定位它们:
.slideshow {
height: 50px;
background: red;
}
.footer {
height: 50px;
background: green;
}
.parent {
position: fixed;
width: 100%;
bottom: 0;
}
<div class="parent">
<div class="slideshow"></div>
<div class="footer"></div>
</div>
希望能帮助到你!
推荐阅读
- c# - WinForm中如何调用AppService
- eloquent - 从日期开始的持续时间内的雄辩的单位总和
- android - Android - 无法从包裹中读取输入通道文件描述符
- c++ - 如何编写返回引用或值的函数模板?
- c# - 检查二进制格式化程序的序列化是否完成
- python - 如何使用 python 在 csv 文件中删除 None 行?
- c# - 尽管向绑定元素添加了 maRecievedMessageSize 属性,但缓冲区超出了 WCF 限制
- git - Git 挂钩预提交仅适用于暂存文件
- angular6 - 角度日期管道从实际日期值中减去一天
- c# - 如何在每个工作表中生成具有不同内容的 Excel epplus C# 新工作表